Test case
3 generated files · +6 −6test/inputs/graphql/github1.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github2.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 131 | 131 | return invalidValue(l(ref || "object"), val, key, parent); |
| 132 | 132 | } |
| 133 | - const result: any = {}; | |
| 133 | + const result: any = Object.create(null); | |
| 134 | 134 | Object.getOwnPropertyNames(props).forEach(key => { |
| 135 | 135 | const prop = props[key]; |
| 136 | 136 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -141,7 +141,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 141 | 141 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 142 | 142 | } |
| 143 | 143 | }); |
| 144 | - return result; | |
| 144 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 131 | 131 | return invalidValue(l(ref || "object"), val, key, parent); |
| 132 | 132 | } |
| 133 | - const result: any = {}; | |
| 133 | + const result: any = Object.create(null); | |
| 134 | 134 | Object.getOwnPropertyNames(props).forEach(key => { |
| 135 | 135 | const prop = props[key]; |
| 136 | 136 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -141,7 +141,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 141 | 141 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 142 | 142 | } |
| 143 | 143 | }); |
| 144 | - return result; | |
| 144 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github3.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 139 | 139 | return invalidValue(l(ref || "object"), val, key, parent); |
| 140 | 140 | } |
| 141 | - const result: any = {}; | |
| 141 | + const result: any = Object.create(null); | |
| 142 | 142 | Object.getOwnPropertyNames(props).forEach(key => { |
| 143 | 143 | const prop = props[key]; |
| 144 | 144 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 150 | 150 | } |
| 151 | 151 | }); |
| 152 | - return result; | |
| 152 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github4.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 140 | 140 | return invalidValue(l(ref || "object"), val, key, parent); |
| 141 | 141 | } |
| 142 | - const result: any = {}; | |
| 142 | + const result: any = Object.create(null); | |
| 143 | 143 | Object.getOwnPropertyNames(props).forEach(key => { |
| 144 | 144 | const prop = props[key]; |
| 145 | 145 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -150,7 +150,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 150 | 150 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 151 | 151 | } |
| 152 | 152 | }); |
| 153 | - return result; | |
| 153 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github5.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github6.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github7.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 143 | 143 | return invalidValue(l(ref || "object"), val, key, parent); |
| 144 | 144 | } |
| 145 | - const result: any = {}; | |
| 145 | + const result: any = Object.create(null); | |
| 146 | 146 | Object.getOwnPropertyNames(props).forEach(key => { |
| 147 | 147 | const prop = props[key]; |
| 148 | 148 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 154 | 154 | } |
| 155 | 155 | }); |
| 156 | - return result; | |
| 156 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 143 | 143 | return invalidValue(l(ref || "object"), val, key, parent); |
| 144 | 144 | } |
| 145 | - const result: any = {}; | |
| 145 | + const result: any = Object.create(null); | |
| 146 | 146 | Object.getOwnPropertyNames(props).forEach(key => { |
| 147 | 147 | const prop = props[key]; |
| 148 | 148 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 154 | 154 | } |
| 155 | 155 | }); |
| 156 | - return result; | |
| 156 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github8.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 131 | 131 | return invalidValue(l(ref || "object"), val, key, parent); |
| 132 | 132 | } |
| 133 | - const result: any = {}; | |
| 133 | + const result: any = Object.create(null); | |
| 134 | 134 | Object.getOwnPropertyNames(props).forEach(key => { |
| 135 | 135 | const prop = props[key]; |
| 136 | 136 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -141,7 +141,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 141 | 141 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 142 | 142 | } |
| 143 | 143 | }); |
| 144 | - return result; | |
| 144 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/graphql/github9.graphql
Mgraphql-flowdefault / TopLevel.js+2 −2
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 140 | 140 | return invalidValue(l(ref || "object"), val, key, parent); |
| 141 | 141 | } |
| 142 | - const result: any = {}; | |
| 142 | + const result: any = Object.create(null); | |
| 143 | 143 | Object.getOwnPropertyNames(props).forEach(key => { |
| 144 | 144 | const prop = props[key]; |
| 145 | 145 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -150,7 +150,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 150 | 150 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 151 | 151 | } |
| 152 | 152 | }); |
| 153 | - return result; | |
| 153 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (typ === "any") return val; |
Mgraphql-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mgraphql-typescriptdefault / TopLevel.ts+2 −2
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 134 | 134 | return invalidValue(l(ref || "object"), val, key, parent); |
| 135 | 135 | } |
| 136 | - const result: any = {}; | |
| 136 | + const result: any = Object.create(null); | |
| 137 | 137 | Object.getOwnPropertyNames(props).forEach(key => { |
| 138 | 138 | const prop = props[key]; |
| 139 | 139 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -144,7 +144,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 144 | 144 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 145 | 145 | } |
| 146 | 146 | }); |
| 147 | - return result; | |
| 147 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/00c36.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeFluffyQuickType x = | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/00ec5.json
Melmdefault / QuickType.elm+9 −1
| @@ -160,7 +160,7 @@ provider = | ||
| 160 | 160 | encodeProvider : Provider -> Jenc.Value |
| 161 | 161 | encodeProvider x = |
| 162 | 162 | Jenc.object |
| 163 | - [ ("properties", Jenc.dict identity encodeProperty x.properties) | |
| 163 | + [ ("properties", makeDictEncoder identity encodeProperty x.properties) | |
| 164 | 164 | ] |
| 165 | 165 | |
| 166 | 166 | property : Jdec.Decoder Property |
| @@ -303,6 +303,14 @@ encodeSchema x = | ||
| 303 | 303 | |
| 304 | 304 | --- encoder helpers |
| 305 | 305 | |
| 306 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 307 | +makeDictEncoder f m r = | |
| 308 | + r | |
| 309 | + |> Dict.toList | |
| 310 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 311 | + |> String.join "," | |
| 312 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 313 | + | |
| 306 | 314 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 307 | 315 | makeNullableEncoder f m = |
| 308 | 316 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -174,7 +174,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 174 | 174 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 175 | 175 | return invalidValue(l(ref || "object"), val, key, parent); |
| 176 | 176 | } |
| 177 | - const result: any = {}; | |
| 177 | + const result: any = Object.create(null); | |
| 178 | 178 | Object.getOwnPropertyNames(props).forEach(key => { |
| 179 | 179 | const prop = props[key]; |
| 180 | 180 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -185,7 +185,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 185 | 185 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 186 | 186 | } |
| 187 | 187 | }); |
| 188 | - return result; | |
| 188 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -173,7 +173,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 173 | 173 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 174 | 174 | return invalidValue(l(ref || "object"), val, key, parent); |
| 175 | 175 | } |
| 176 | - const result: any = {}; | |
| 176 | + const result: any = Object.create(null); | |
| 177 | 177 | Object.getOwnPropertyNames(props).forEach(key => { |
| 178 | 178 | const prop = props[key]; |
| 179 | 179 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -184,7 +184,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 184 | 184 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 185 | 185 | } |
| 186 | 186 | }); |
| 187 | - return result; | |
| 187 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/010b1.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/016af.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/033b1.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/050b0.json
Melmdefault / QuickType.elm+8 −0
| @@ -274,6 +274,14 @@ encodeTitle x = case x of | ||
| 274 | 274 | |
| 275 | 275 | --- encoder helpers |
| 276 | 276 | |
| 277 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 278 | +makeDictEncoder f m r = | |
| 279 | + r | |
| 280 | + |> Dict.toList | |
| 281 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 282 | + |> String.join "," | |
| 283 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 284 | + | |
| 277 | 285 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 278 | 286 | makeNullableEncoder f m = |
| 279 | 287 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -163,7 +163,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 163 | 163 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 164 | 164 | return invalidValue(l(ref || "object"), val, key, parent); |
| 165 | 165 | } |
| 166 | - const result: any = {}; | |
| 166 | + const result: any = Object.create(null); | |
| 167 | 167 | Object.getOwnPropertyNames(props).forEach(key => { |
| 168 | 168 | const prop = props[key]; |
| 169 | 169 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -174,7 +174,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 174 | 174 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 175 | 175 | } |
| 176 | 176 | }); |
| 177 | - return result; | |
| 177 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/06bee.json
Melmdefault / QuickType.elm+8 −0
| @@ -234,6 +234,14 @@ encodeTitle x = case x of | ||
| 234 | 234 | |
| 235 | 235 | --- encoder helpers |
| 236 | 236 | |
| 237 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 238 | +makeDictEncoder f m r = | |
| 239 | + r | |
| 240 | + |> Dict.toList | |
| 241 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 242 | + |> String.join "," | |
| 243 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 244 | + | |
| 237 | 245 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 238 | 246 | makeNullableEncoder f m = |
| 239 | 247 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 152 | 152 | return invalidValue(l(ref || "object"), val, key, parent); |
| 153 | 153 | } |
| 154 | - const result: any = {}; | |
| 154 | + const result: any = Object.create(null); | |
| 155 | 155 | Object.getOwnPropertyNames(props).forEach(key => { |
| 156 | 156 | const prop = props[key]; |
| 157 | 157 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -162,7 +162,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 162 | 162 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 163 | 163 | } |
| 164 | 164 | }); |
| 165 | - return result; | |
| 165 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 143 | 143 | return invalidValue(l(ref || "object"), val, key, parent); |
| 144 | 144 | } |
| 145 | - const result: any = {}; | |
| 145 | + const result: any = Object.create(null); | |
| 146 | 146 | Object.getOwnPropertyNames(props).forEach(key => { |
| 147 | 147 | const prop = props[key]; |
| 148 | 148 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 154 | 154 | } |
| 155 | 155 | }); |
| 156 | - return result; | |
| 156 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/07540.json
Melmdefault / QuickType.elm+8 −0
| @@ -65,6 +65,14 @@ encodeCookies x = | ||
| 65 | 65 | |
| 66 | 66 | --- encoder helpers |
| 67 | 67 | |
| 68 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 69 | +makeDictEncoder f m r = | |
| 70 | + r | |
| 71 | + |> Dict.toList | |
| 72 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 73 | + |> String.join "," | |
| 74 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 75 | + | |
| 68 | 76 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 69 | 77 | makeNullableEncoder f m = |
| 70 | 78 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0779f.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/07c75.json
Melmdefault / QuickType.elm+8 −0
| @@ -137,6 +137,14 @@ encodeText x = | ||
| 137 | 137 | |
| 138 | 138 | --- encoder helpers |
| 139 | 139 | |
| 140 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 141 | +makeDictEncoder f m r = | |
| 142 | + r | |
| 143 | + |> Dict.toList | |
| 144 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 145 | + |> String.join "," | |
| 146 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 147 | + | |
| 140 | 148 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 141 | 149 | makeNullableEncoder f m = |
| 142 | 150 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/09f54.json
Melmdefault / QuickType.elm+9 −1
| @@ -61,7 +61,7 @@ quickType = | ||
| 61 | 61 | encodeQuickType : QuickType -> Jenc.Value |
| 62 | 62 | encodeQuickType x = |
| 63 | 63 | Jenc.object |
| 64 | - [ ("data", Jenc.dict identity encodeDatum x.data) | |
| 64 | + [ ("data", makeDictEncoder identity encodeDatum x.data) | |
| 65 | 65 | , ("description", encodeDescription x.description) |
| 66 | 66 | ] |
| 67 | 67 | |
| @@ -97,6 +97,14 @@ encodeDescription x = | ||
| 97 | 97 | |
| 98 | 98 | --- encoder helpers |
| 99 | 99 | |
| 100 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 101 | +makeDictEncoder f m r = | |
| 102 | + r | |
| 103 | + |> Dict.toList | |
| 104 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 105 | + |> String.join "," | |
| 106 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 107 | + | |
| 100 | 108 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 101 | 109 | makeNullableEncoder f m = |
| 102 | 110 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0a358.json
Melmdefault / QuickType.elm+8 −0
| @@ -114,6 +114,14 @@ encodeResult x = | ||
| 114 | 114 | |
| 115 | 115 | --- encoder helpers |
| 116 | 116 | |
| 117 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 118 | +makeDictEncoder f m r = | |
| 119 | + r | |
| 120 | + |> Dict.toList | |
| 121 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 122 | + |> String.join "," | |
| 123 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 124 | + | |
| 117 | 125 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 118 | 126 | makeNullableEncoder f m = |
| 119 | 127 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 126 | 126 | return invalidValue(l(ref || "object"), val, key, parent); |
| 127 | 127 | } |
| 128 | - const result: any = {}; | |
| 128 | + const result: any = Object.create(null); | |
| 129 | 129 | Object.getOwnPropertyNames(props).forEach(key => { |
| 130 | 130 | const prop = props[key]; |
| 131 | 131 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 137 | 137 | } |
| 138 | 138 | }); |
| 139 | - return result; | |
| 139 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 123 | 123 | return invalidValue(l(ref || "object"), val, key, parent); |
| 124 | 124 | } |
| 125 | - const result: any = {}; | |
| 125 | + const result: any = Object.create(null); | |
| 126 | 126 | Object.getOwnPropertyNames(props).forEach(key => { |
| 127 | 127 | const prop = props[key]; |
| 128 | 128 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 134 | 134 | } |
| 135 | 135 | }); |
| 136 | - return result; | |
| 136 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0a91a.json
Melmdefault / QuickType.elm+8 −0
| @@ -762,6 +762,14 @@ encodeQuickTypeRepo x = | ||
| 762 | 762 | |
| 763 | 763 | --- encoder helpers |
| 764 | 764 | |
| 765 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 766 | +makeDictEncoder f m r = | |
| 767 | + r | |
| 768 | + |> Dict.toList | |
| 769 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 770 | + |> String.join "," | |
| 771 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 772 | + | |
| 765 | 773 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 766 | 774 | makeNullableEncoder f m = |
| 767 | 775 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -327,7 +327,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 327 | 327 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 328 | 328 | return invalidValue(l(ref || "object"), val, key, parent); |
| 329 | 329 | } |
| 330 | - const result: any = {}; | |
| 330 | + const result: any = Object.create(null); | |
| 331 | 331 | Object.getOwnPropertyNames(props).forEach(key => { |
| 332 | 332 | const prop = props[key]; |
| 333 | 333 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -338,7 +338,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 338 | 338 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 339 | 339 | } |
| 340 | 340 | }); |
| 341 | - return result; | |
| 341 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -322,7 +322,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 322 | 322 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 323 | 323 | return invalidValue(l(ref || "object"), val, key, parent); |
| 324 | 324 | } |
| 325 | - const result: any = {}; | |
| 325 | + const result: any = Object.create(null); | |
| 326 | 326 | Object.getOwnPropertyNames(props).forEach(key => { |
| 327 | 327 | const prop = props[key]; |
| 328 | 328 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -333,7 +333,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 333 | 333 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 334 | 334 | } |
| 335 | 335 | }); |
| 336 | - return result; | |
| 336 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0b91a.json
Melmdefault / QuickType.elm+8 −0
| @@ -190,6 +190,14 @@ encodeComponent x = | ||
| 190 | 190 | |
| 191 | 191 | --- encoder helpers |
| 192 | 192 | |
| 193 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 194 | +makeDictEncoder f m r = | |
| 195 | + r | |
| 196 | + |> Dict.toList | |
| 197 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 198 | + |> String.join "," | |
| 199 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 200 | + | |
| 193 | 201 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 194 | 202 | makeNullableEncoder f m = |
| 195 | 203 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0cffa.json
Melmdefault / QuickType.elm+8 −0
| @@ -455,6 +455,14 @@ encodePagination x = | ||
| 455 | 455 | |
| 456 | 456 | --- encoder helpers |
| 457 | 457 | |
| 458 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 459 | +makeDictEncoder f m r = | |
| 460 | + r | |
| 461 | + |> Dict.toList | |
| 462 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 463 | + |> String.join "," | |
| 464 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 465 | + | |
| 458 | 466 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 459 | 467 | makeNullableEncoder f m = |
| 460 | 468 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -222,7 +222,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 222 | 222 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 223 | 223 | return invalidValue(l(ref || "object"), val, key, parent); |
| 224 | 224 | } |
| 225 | - const result: any = {}; | |
| 225 | + const result: any = Object.create(null); | |
| 226 | 226 | Object.getOwnPropertyNames(props).forEach(key => { |
| 227 | 227 | const prop = props[key]; |
| 228 | 228 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -233,7 +233,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 233 | 233 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 234 | 234 | } |
| 235 | 235 | }); |
| 236 | - return result; | |
| 236 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -215,7 +215,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 215 | 215 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 216 | 216 | return invalidValue(l(ref || "object"), val, key, parent); |
| 217 | 217 | } |
| 218 | - const result: any = {}; | |
| 218 | + const result: any = Object.create(null); | |
| 219 | 219 | Object.getOwnPropertyNames(props).forEach(key => { |
| 220 | 220 | const prop = props[key]; |
| 221 | 221 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 227 | 227 | } |
| 228 | 228 | }); |
| 229 | - return result; | |
| 229 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0e0c2.json
Melmdefault / QuickType.elm+8 −0
| @@ -333,6 +333,14 @@ encodeVoteScore x = | ||
| 333 | 333 | |
| 334 | 334 | --- encoder helpers |
| 335 | 335 | |
| 336 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 337 | +makeDictEncoder f m r = | |
| 338 | + r | |
| 339 | + |> Dict.toList | |
| 340 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 341 | + |> String.join "," | |
| 342 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 343 | + | |
| 336 | 344 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 337 | 345 | makeNullableEncoder f m = |
| 338 | 346 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -184,7 +184,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 184 | 184 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 185 | 185 | return invalidValue(l(ref || "object"), val, key, parent); |
| 186 | 186 | } |
| 187 | - const result: any = {}; | |
| 187 | + const result: any = Object.create(null); | |
| 188 | 188 | Object.getOwnPropertyNames(props).forEach(key => { |
| 189 | 189 | const prop = props[key]; |
| 190 | 190 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -195,7 +195,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 195 | 195 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 196 | 196 | } |
| 197 | 197 | }); |
| 198 | - return result; | |
| 198 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -178,7 +178,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 178 | 178 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 179 | 179 | return invalidValue(l(ref || "object"), val, key, parent); |
| 180 | 180 | } |
| 181 | - const result: any = {}; | |
| 181 | + const result: any = Object.create(null); | |
| 182 | 182 | Object.getOwnPropertyNames(props).forEach(key => { |
| 183 | 183 | const prop = props[key]; |
| 184 | 184 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -189,7 +189,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 189 | 189 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 190 | 190 | } |
| 191 | 191 | }); |
| 192 | - return result; | |
| 192 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/0fecf.json
Melmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/10be4.json
Melmdefault / QuickType.elm+8 −0
| @@ -307,6 +307,14 @@ encodeTitle x = case x of | ||
| 307 | 307 | |
| 308 | 308 | --- encoder helpers |
| 309 | 309 | |
| 310 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 311 | +makeDictEncoder f m r = | |
| 312 | + r | |
| 313 | + |> Dict.toList | |
| 314 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 315 | + |> String.join "," | |
| 316 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 317 | + | |
| 310 | 318 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 311 | 319 | makeNullableEncoder f m = |
| 312 | 320 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -174,7 +174,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 174 | 174 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 175 | 175 | return invalidValue(l(ref || "object"), val, key, parent); |
| 176 | 176 | } |
| 177 | - const result: any = {}; | |
| 177 | + const result: any = Object.create(null); | |
| 178 | 178 | Object.getOwnPropertyNames(props).forEach(key => { |
| 179 | 179 | const prop = props[key]; |
| 180 | 180 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -185,7 +185,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 185 | 185 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 186 | 186 | } |
| 187 | 187 | }); |
| 188 | - return result; | |
| 188 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/112b5.json
Melmdefault / QuickType.elm+8 −0
| @@ -99,6 +99,14 @@ encodeHeaders x = | ||
| 99 | 99 | |
| 100 | 100 | --- encoder helpers |
| 101 | 101 | |
| 102 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 103 | +makeDictEncoder f m r = | |
| 104 | + r | |
| 105 | + |> Dict.toList | |
| 106 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 107 | + |> String.join "," | |
| 108 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 109 | + | |
| 102 | 110 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 103 | 111 | makeNullableEncoder f m = |
| 104 | 112 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/127a1.json
Melmdefault / QuickType.elm+8 −0
| @@ -452,6 +452,14 @@ encodePagination x = | ||
| 452 | 452 | |
| 453 | 453 | --- encoder helpers |
| 454 | 454 | |
| 455 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 456 | +makeDictEncoder f m r = | |
| 457 | + r | |
| 458 | + |> Dict.toList | |
| 459 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 460 | + |> String.join "," | |
| 461 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 462 | + | |
| 455 | 463 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 456 | 464 | makeNullableEncoder f m = |
| 457 | 465 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -221,7 +221,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 221 | 221 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 222 | 222 | return invalidValue(l(ref || "object"), val, key, parent); |
| 223 | 223 | } |
| 224 | - const result: any = {}; | |
| 224 | + const result: any = Object.create(null); | |
| 225 | 225 | Object.getOwnPropertyNames(props).forEach(key => { |
| 226 | 226 | const prop = props[key]; |
| 227 | 227 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -232,7 +232,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 232 | 232 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 233 | 233 | } |
| 234 | 234 | }); |
| 235 | - return result; | |
| 235 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -215,7 +215,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 215 | 215 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 216 | 216 | return invalidValue(l(ref || "object"), val, key, parent); |
| 217 | 217 | } |
| 218 | - const result: any = {}; | |
| 218 | + const result: any = Object.create(null); | |
| 219 | 219 | Object.getOwnPropertyNames(props).forEach(key => { |
| 220 | 220 | const prop = props[key]; |
| 221 | 221 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 227 | 227 | } |
| 228 | 228 | }); |
| 229 | - return result; | |
| 229 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/13d8d.json
Melmdefault / QuickType.elm+8 −0
| @@ -140,6 +140,14 @@ encodeOutcomeStatus x = | ||
| 140 | 140 | |
| 141 | 141 | --- encoder helpers |
| 142 | 142 | |
| 143 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 144 | +makeDictEncoder f m r = | |
| 145 | + r | |
| 146 | + |> Dict.toList | |
| 147 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 148 | + |> String.join "," | |
| 149 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 150 | + | |
| 143 | 151 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 144 | 152 | makeNullableEncoder f m = |
| 145 | 153 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 134 | 134 | return invalidValue(l(ref || "object"), val, key, parent); |
| 135 | 135 | } |
| 136 | - const result: any = {}; | |
| 136 | + const result: any = Object.create(null); | |
| 137 | 137 | Object.getOwnPropertyNames(props).forEach(key => { |
| 138 | 138 | const prop = props[key]; |
| 139 | 139 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -144,7 +144,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 144 | 144 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 145 | 145 | } |
| 146 | 146 | }); |
| 147 | - return result; | |
| 147 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 134 | 134 | return invalidValue(l(ref || "object"), val, key, parent); |
| 135 | 135 | } |
| 136 | - const result: any = {}; | |
| 136 | + const result: any = Object.create(null); | |
| 137 | 137 | Object.getOwnPropertyNames(props).forEach(key => { |
| 138 | 138 | const prop = props[key]; |
| 139 | 139 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -144,7 +144,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 144 | 144 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 145 | 145 | } |
| 146 | 146 | }); |
| 147 | - return result; | |
| 147 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/14d38.json
Melmdefault / QuickType.elm+8 −0
| @@ -75,6 +75,14 @@ encodeHeaders x = | ||
| 75 | 75 | |
| 76 | 76 | --- encoder helpers |
| 77 | 77 | |
| 78 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 79 | +makeDictEncoder f m r = | |
| 80 | + r | |
| 81 | + |> Dict.toList | |
| 82 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 83 | + |> String.join "," | |
| 84 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 85 | + | |
| 78 | 86 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 79 | 87 | makeNullableEncoder f m = |
| 80 | 88 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/167d6.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/16bc5.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/176f1.json
Melmdefault / QuickType.elm+8 −0
| @@ -141,6 +141,14 @@ encodeFootnote x = | ||
| 141 | 141 | |
| 142 | 142 | --- encoder helpers |
| 143 | 143 | |
| 144 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 145 | +makeDictEncoder f m r = | |
| 146 | + r | |
| 147 | + |> Dict.toList | |
| 148 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 149 | + |> String.join "," | |
| 150 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 151 | + | |
| 144 | 152 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 145 | 153 | makeNullableEncoder f m = |
| 146 | 154 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/1a7f5.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/1b28c.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/1b409.json
Melmdefault / QuickType.elm+8 −0
| @@ -395,6 +395,14 @@ encodeTitle x = case x of | ||
| 395 | 395 | |
| 396 | 396 | --- encoder helpers |
| 397 | 397 | |
| 398 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 399 | +makeDictEncoder f m r = | |
| 400 | + r | |
| 401 | + |> Dict.toList | |
| 402 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 403 | + |> String.join "," | |
| 404 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 405 | + | |
| 398 | 406 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 399 | 407 | makeNullableEncoder f m = |
| 400 | 408 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -198,7 +198,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 198 | 198 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 199 | 199 | return invalidValue(l(ref || "object"), val, key, parent); |
| 200 | 200 | } |
| 201 | - const result: any = {}; | |
| 201 | + const result: any = Object.create(null); | |
| 202 | 202 | Object.getOwnPropertyNames(props).forEach(key => { |
| 203 | 203 | const prop = props[key]; |
| 204 | 204 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -209,7 +209,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 209 | 209 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 210 | 210 | } |
| 211 | 211 | }); |
| 212 | - return result; | |
| 212 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -181,7 +181,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 181 | 181 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 182 | 182 | return invalidValue(l(ref || "object"), val, key, parent); |
| 183 | 183 | } |
| 184 | - const result: any = {}; | |
| 184 | + const result: any = Object.create(null); | |
| 185 | 185 | Object.getOwnPropertyNames(props).forEach(key => { |
| 186 | 186 | const prop = props[key]; |
| 187 | 187 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -192,7 +192,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 192 | 192 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 193 | 193 | } |
| 194 | 194 | }); |
| 195 | - return result; | |
| 195 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/2465e.json
Melmdefault / QuickType.elm+8 −0
| @@ -317,6 +317,14 @@ encodeSchema x = | ||
| 317 | 317 | |
| 318 | 318 | --- encoder helpers |
| 319 | 319 | |
| 320 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 321 | +makeDictEncoder f m r = | |
| 322 | + r | |
| 323 | + |> Dict.toList | |
| 324 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 325 | + |> String.join "," | |
| 326 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 327 | + | |
| 320 | 328 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 321 | 329 | makeNullableEncoder f m = |
| 322 | 330 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -180,7 +180,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 180 | 180 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 181 | 181 | return invalidValue(l(ref || "object"), val, key, parent); |
| 182 | 182 | } |
| 183 | - const result: any = {}; | |
| 183 | + const result: any = Object.create(null); | |
| 184 | 184 | Object.getOwnPropertyNames(props).forEach(key => { |
| 185 | 185 | const prop = props[key]; |
| 186 | 186 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -191,7 +191,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 191 | 191 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 192 | 192 | } |
| 193 | 193 | }); |
| 194 | - return result; | |
| 194 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -180,7 +180,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 180 | 180 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 181 | 181 | return invalidValue(l(ref || "object"), val, key, parent); |
| 182 | 182 | } |
| 183 | - const result: any = {}; | |
| 183 | + const result: any = Object.create(null); | |
| 184 | 184 | Object.getOwnPropertyNames(props).forEach(key => { |
| 185 | 185 | const prop = props[key]; |
| 186 | 186 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -191,7 +191,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 191 | 191 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 192 | 192 | } |
| 193 | 193 | }); |
| 194 | - return result; | |
| 194 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/24f52.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/262f0.json
Melmdefault / QuickType.elm+8 −0
| @@ -419,6 +419,14 @@ encodeWind x = | ||
| 419 | 419 | |
| 420 | 420 | --- encoder helpers |
| 421 | 421 | |
| 422 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 423 | +makeDictEncoder f m r = | |
| 424 | + r | |
| 425 | + |> Dict.toList | |
| 426 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 427 | + |> String.join "," | |
| 428 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 429 | + | |
| 422 | 430 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 423 | 431 | makeNullableEncoder f m = |
| 424 | 432 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -210,7 +210,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 210 | 210 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 211 | 211 | return invalidValue(l(ref || "object"), val, key, parent); |
| 212 | 212 | } |
| 213 | - const result: any = {}; | |
| 213 | + const result: any = Object.create(null); | |
| 214 | 214 | Object.getOwnPropertyNames(props).forEach(key => { |
| 215 | 215 | const prop = props[key]; |
| 216 | 216 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -221,7 +221,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 221 | 221 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 222 | 222 | } |
| 223 | 223 | }); |
| 224 | - return result; | |
| 224 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -207,7 +207,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 207 | 207 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 208 | 208 | return invalidValue(l(ref || "object"), val, key, parent); |
| 209 | 209 | } |
| 210 | - const result: any = {}; | |
| 210 | + const result: any = Object.create(null); | |
| 211 | 211 | Object.getOwnPropertyNames(props).forEach(key => { |
| 212 | 212 | const prop = props[key]; |
| 213 | 213 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -218,7 +218,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 218 | 218 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 219 | 219 | } |
| 220 | 220 | }); |
| 221 | - return result; | |
| 221 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/26b49.json
Melmdefault / QuickType.elm+8 −0
| @@ -438,6 +438,14 @@ encodePagination x = | ||
| 438 | 438 | |
| 439 | 439 | --- encoder helpers |
| 440 | 440 | |
| 441 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 442 | +makeDictEncoder f m r = | |
| 443 | + r | |
| 444 | + |> Dict.toList | |
| 445 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 446 | + |> String.join "," | |
| 447 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 448 | + | |
| 441 | 449 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 442 | 450 | makeNullableEncoder f m = |
| 443 | 451 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -219,7 +219,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 219 | 219 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 220 | 220 | return invalidValue(l(ref || "object"), val, key, parent); |
| 221 | 221 | } |
| 222 | - const result: any = {}; | |
| 222 | + const result: any = Object.create(null); | |
| 223 | 223 | Object.getOwnPropertyNames(props).forEach(key => { |
| 224 | 224 | const prop = props[key]; |
| 225 | 225 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -230,7 +230,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 230 | 230 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 231 | 231 | } |
| 232 | 232 | }); |
| 233 | - return result; | |
| 233 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -214,7 +214,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 214 | 214 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 215 | 215 | return invalidValue(l(ref || "object"), val, key, parent); |
| 216 | 216 | } |
| 217 | - const result: any = {}; | |
| 217 | + const result: any = Object.create(null); | |
| 218 | 218 | Object.getOwnPropertyNames(props).forEach(key => { |
| 219 | 219 | const prop = props[key]; |
| 220 | 220 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -225,7 +225,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 225 | 225 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 226 | 226 | } |
| 227 | 227 | }); |
| 228 | - return result; | |
| 228 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/26c9c.json
Melmdefault / QuickType.elm+8 −0
| @@ -717,6 +717,14 @@ encodeExpression x = | ||
| 717 | 717 | |
| 718 | 718 | --- encoder helpers |
| 719 | 719 | |
| 720 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 721 | +makeDictEncoder f m r = | |
| 722 | + r | |
| 723 | + |> Dict.toList | |
| 724 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 725 | + |> String.join "," | |
| 726 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 727 | + | |
| 720 | 728 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 721 | 729 | makeNullableEncoder f m = |
| 722 | 730 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -294,7 +294,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 294 | 294 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 295 | 295 | return invalidValue(l(ref || "object"), val, key, parent); |
| 296 | 296 | } |
| 297 | - const result: any = {}; | |
| 297 | + const result: any = Object.create(null); | |
| 298 | 298 | Object.getOwnPropertyNames(props).forEach(key => { |
| 299 | 299 | const prop = props[key]; |
| 300 | 300 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -305,7 +305,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 305 | 305 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 306 | 306 | } |
| 307 | 307 | }); |
| 308 | - return result; | |
| 308 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -294,7 +294,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 294 | 294 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 295 | 295 | return invalidValue(l(ref || "object"), val, key, parent); |
| 296 | 296 | } |
| 297 | - const result: any = {}; | |
| 297 | + const result: any = Object.create(null); | |
| 298 | 298 | Object.getOwnPropertyNames(props).forEach(key => { |
| 299 | 299 | const prop = props[key]; |
| 300 | 300 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -305,7 +305,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 305 | 305 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 306 | 306 | } |
| 307 | 307 | }); |
| 308 | - return result; | |
| 308 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/27332.json
Melmdefault / QuickType.elm+8 −0
| @@ -607,6 +607,14 @@ encodeKind x = case x of | ||
| 607 | 607 | |
| 608 | 608 | --- encoder helpers |
| 609 | 609 | |
| 610 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 611 | +makeDictEncoder f m r = | |
| 612 | + r | |
| 613 | + |> Dict.toList | |
| 614 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 615 | + |> String.join "," | |
| 616 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 617 | + | |
| 610 | 618 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 611 | 619 | makeNullableEncoder f m = |
| 612 | 620 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -260,7 +260,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 260 | 260 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 261 | 261 | return invalidValue(l(ref || "object"), val, key, parent); |
| 262 | 262 | } |
| 263 | - const result: any = {}; | |
| 263 | + const result: any = Object.create(null); | |
| 264 | 264 | Object.getOwnPropertyNames(props).forEach(key => { |
| 265 | 265 | const prop = props[key]; |
| 266 | 266 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -271,7 +271,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 271 | 271 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 272 | 272 | } |
| 273 | 273 | }); |
| 274 | - return result; | |
| 274 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -246,7 +246,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 246 | 246 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 247 | 247 | return invalidValue(l(ref || "object"), val, key, parent); |
| 248 | 248 | } |
| 249 | - const result: any = {}; | |
| 249 | + const result: any = Object.create(null); | |
| 250 | 250 | Object.getOwnPropertyNames(props).forEach(key => { |
| 251 | 251 | const prop = props[key]; |
| 252 | 252 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -257,7 +257,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 257 | 257 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 258 | 258 | } |
| 259 | 259 | }); |
| 260 | - return result; | |
| 260 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/29f47.json
Melmdefault / QuickType.elm+8 −0
| @@ -580,6 +580,14 @@ encodeKind x = case x of | ||
| 580 | 580 | |
| 581 | 581 | --- encoder helpers |
| 582 | 582 | |
| 583 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 584 | +makeDictEncoder f m r = | |
| 585 | + r | |
| 586 | + |> Dict.toList | |
| 587 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 588 | + |> String.join "," | |
| 589 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 590 | + | |
| 583 | 591 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 584 | 592 | makeNullableEncoder f m = |
| 585 | 593 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -246,7 +246,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 246 | 246 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 247 | 247 | return invalidValue(l(ref || "object"), val, key, parent); |
| 248 | 248 | } |
| 249 | - const result: any = {}; | |
| 249 | + const result: any = Object.create(null); | |
| 250 | 250 | Object.getOwnPropertyNames(props).forEach(key => { |
| 251 | 251 | const prop = props[key]; |
| 252 | 252 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -257,7 +257,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 257 | 257 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 258 | 258 | } |
| 259 | 259 | }); |
| 260 | - return result; | |
| 260 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -233,7 +233,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 233 | 233 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 234 | 234 | return invalidValue(l(ref || "object"), val, key, parent); |
| 235 | 235 | } |
| 236 | - const result: any = {}; | |
| 236 | + const result: any = Object.create(null); | |
| 237 | 237 | Object.getOwnPropertyNames(props).forEach(key => { |
| 238 | 238 | const prop = props[key]; |
| 239 | 239 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -244,7 +244,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 244 | 244 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 245 | 245 | } |
| 246 | 246 | }); |
| 247 | - return result; | |
| 247 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/2d4e2.json
Melmdefault / QuickType.elm+8 −0
| @@ -475,6 +475,14 @@ encodeTitle x = case x of | ||
| 475 | 475 | |
| 476 | 476 | --- encoder helpers |
| 477 | 477 | |
| 478 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 479 | +makeDictEncoder f m r = | |
| 480 | + r | |
| 481 | + |> Dict.toList | |
| 482 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 483 | + |> String.join "," | |
| 484 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 485 | + | |
| 478 | 486 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 479 | 487 | makeNullableEncoder f m = |
| 480 | 488 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -214,7 +214,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 214 | 214 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 215 | 215 | return invalidValue(l(ref || "object"), val, key, parent); |
| 216 | 216 | } |
| 217 | - const result: any = {}; | |
| 217 | + const result: any = Object.create(null); | |
| 218 | 218 | Object.getOwnPropertyNames(props).forEach(key => { |
| 219 | 219 | const prop = props[key]; |
| 220 | 220 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -225,7 +225,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 225 | 225 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 226 | 226 | } |
| 227 | 227 | }); |
| 228 | - return result; | |
| 228 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -191,7 +191,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 191 | 191 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 192 | 192 | return invalidValue(l(ref || "object"), val, key, parent); |
| 193 | 193 | } |
| 194 | - const result: any = {}; | |
| 194 | + const result: any = Object.create(null); | |
| 195 | 195 | Object.getOwnPropertyNames(props).forEach(key => { |
| 196 | 196 | const prop = props[key]; |
| 197 | 197 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -202,7 +202,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 202 | 202 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 203 | 203 | } |
| 204 | 204 | }); |
| 205 | - return result; | |
| 205 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/2df80.json
Melmdefault / QuickType.elm+8 −0
| @@ -304,6 +304,14 @@ encodeFluffyQuickType x = | ||
| 304 | 304 | |
| 305 | 305 | --- encoder helpers |
| 306 | 306 | |
| 307 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 308 | +makeDictEncoder f m r = | |
| 309 | + r | |
| 310 | + |> Dict.toList | |
| 311 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 312 | + |> String.join "," | |
| 313 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 314 | + | |
| 307 | 315 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 308 | 316 | makeNullableEncoder f m = |
| 309 | 317 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -180,7 +180,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 180 | 180 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 181 | 181 | return invalidValue(l(ref || "object"), val, key, parent); |
| 182 | 182 | } |
| 183 | - const result: any = {}; | |
| 183 | + const result: any = Object.create(null); | |
| 184 | 184 | Object.getOwnPropertyNames(props).forEach(key => { |
| 185 | 185 | const prop = props[key]; |
| 186 | 186 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -191,7 +191,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 191 | 191 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 192 | 192 | } |
| 193 | 193 | }); |
| 194 | - return result; | |
| 194 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/31189.json
Melmdefault / QuickType.elm+8 −0
| @@ -131,6 +131,14 @@ encodeRates x = | ||
| 131 | 131 | |
| 132 | 132 | --- encoder helpers |
| 133 | 133 | |
| 134 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 135 | +makeDictEncoder f m r = | |
| 136 | + r | |
| 137 | + |> Dict.toList | |
| 138 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 139 | + |> String.join "," | |
| 140 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 141 | + | |
| 134 | 142 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 135 | 143 | makeNullableEncoder f m = |
| 136 | 144 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 135 | 135 | return invalidValue(l(ref || "object"), val, key, parent); |
| 136 | 136 | } |
| 137 | - const result: any = {}; | |
| 137 | + const result: any = Object.create(null); | |
| 138 | 138 | Object.getOwnPropertyNames(props).forEach(key => { |
| 139 | 139 | const prop = props[key]; |
| 140 | 140 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -145,7 +145,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 145 | 145 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 146 | 146 | } |
| 147 | 147 | }); |
| 148 | - return result; | |
| 148 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/32431.json
Melmdefault / QuickType.elm+8 −0
| @@ -319,6 +319,14 @@ encodeMetadata x = | ||
| 319 | 319 | |
| 320 | 320 | --- encoder helpers |
| 321 | 321 | |
| 322 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 323 | +makeDictEncoder f m r = | |
| 324 | + r | |
| 325 | + |> Dict.toList | |
| 326 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 327 | + |> String.join "," | |
| 328 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 329 | + | |
| 322 | 330 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 323 | 331 | makeNullableEncoder f m = |
| 324 | 332 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -178,7 +178,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 178 | 178 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 179 | 179 | return invalidValue(l(ref || "object"), val, key, parent); |
| 180 | 180 | } |
| 181 | - const result: any = {}; | |
| 181 | + const result: any = Object.create(null); | |
| 182 | 182 | Object.getOwnPropertyNames(props).forEach(key => { |
| 183 | 183 | const prop = props[key]; |
| 184 | 184 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -189,7 +189,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 189 | 189 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 190 | 190 | } |
| 191 | 191 | }); |
| 192 | - return result; | |
| 192 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -170,7 +170,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 170 | 170 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 171 | 171 | return invalidValue(l(ref || "object"), val, key, parent); |
| 172 | 172 | } |
| 173 | - const result: any = {}; | |
| 173 | + const result: any = Object.create(null); | |
| 174 | 174 | Object.getOwnPropertyNames(props).forEach(key => { |
| 175 | 175 | const prop = props[key]; |
| 176 | 176 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -181,7 +181,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 181 | 181 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 182 | 182 | } |
| 183 | 183 | }); |
| 184 | - return result; | |
| 184 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/32d5c.json
Melmdefault / QuickType.elm+8 −0
| @@ -77,6 +77,14 @@ encodeQuickTypeElement x = | ||
| 77 | 77 | |
| 78 | 78 | --- encoder helpers |
| 79 | 79 | |
| 80 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 81 | +makeDictEncoder f m r = | |
| 82 | + r | |
| 83 | + |> Dict.toList | |
| 84 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 85 | + |> String.join "," | |
| 86 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 87 | + | |
| 80 | 88 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 81 | 89 | makeNullableEncoder f m = |
| 82 | 90 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/337ed.json
Melmdefault / QuickType.elm+8 −0
| @@ -292,6 +292,14 @@ encodeResultType x = case x of | ||
| 292 | 292 | |
| 293 | 293 | --- encoder helpers |
| 294 | 294 | |
| 295 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 296 | +makeDictEncoder f m r = | |
| 297 | + r | |
| 298 | + |> Dict.toList | |
| 299 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 300 | + |> String.join "," | |
| 301 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 302 | + | |
| 295 | 303 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 296 | 304 | makeNullableEncoder f m = |
| 297 | 305 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -175,7 +175,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 175 | 175 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 176 | 176 | return invalidValue(l(ref || "object"), val, key, parent); |
| 177 | 177 | } |
| 178 | - const result: any = {}; | |
| 178 | + const result: any = Object.create(null); | |
| 179 | 179 | Object.getOwnPropertyNames(props).forEach(key => { |
| 180 | 180 | const prop = props[key]; |
| 181 | 181 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -186,7 +186,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 186 | 186 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 187 | 187 | } |
| 188 | 188 | }); |
| 189 | - return result; | |
| 189 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -165,7 +165,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 165 | 165 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 166 | 166 | return invalidValue(l(ref || "object"), val, key, parent); |
| 167 | 167 | } |
| 168 | - const result: any = {}; | |
| 168 | + const result: any = Object.create(null); | |
| 169 | 169 | Object.getOwnPropertyNames(props).forEach(key => { |
| 170 | 170 | const prop = props[key]; |
| 171 | 171 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -176,7 +176,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 176 | 176 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 177 | 177 | } |
| 178 | 178 | }); |
| 179 | - return result; | |
| 179 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/33d2e.json
Melmdefault / QuickType.elm+8 −0
| @@ -227,6 +227,14 @@ encodeCategory x = case x of | ||
| 227 | 227 | |
| 228 | 228 | --- encoder helpers |
| 229 | 229 | |
| 230 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 231 | +makeDictEncoder f m r = | |
| 232 | + r | |
| 233 | + |> Dict.toList | |
| 234 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 235 | + |> String.join "," | |
| 236 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 237 | + | |
| 230 | 238 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 231 | 239 | makeNullableEncoder f m = |
| 232 | 240 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -160,7 +160,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 160 | 160 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 161 | 161 | return invalidValue(l(ref || "object"), val, key, parent); |
| 162 | 162 | } |
| 163 | - const result: any = {}; | |
| 163 | + const result: any = Object.create(null); | |
| 164 | 164 | Object.getOwnPropertyNames(props).forEach(key => { |
| 165 | 165 | const prop = props[key]; |
| 166 | 166 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -171,7 +171,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 171 | 171 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 172 | 172 | } |
| 173 | 173 | }); |
| 174 | - return result; | |
| 174 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -148,7 +148,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 148 | 148 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 149 | 149 | return invalidValue(l(ref || "object"), val, key, parent); |
| 150 | 150 | } |
| 151 | - const result: any = {}; | |
| 151 | + const result: any = Object.create(null); | |
| 152 | 152 | Object.getOwnPropertyNames(props).forEach(key => { |
| 153 | 153 | const prop = props[key]; |
| 154 | 154 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -159,7 +159,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 159 | 159 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 160 | 160 | } |
| 161 | 161 | }); |
| 162 | - return result; | |
| 162 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/34702.json
Melmdefault / QuickType.elm+8 −0
| @@ -382,6 +382,14 @@ encodeRegion x = case x of | ||
| 382 | 382 | |
| 383 | 383 | --- encoder helpers |
| 384 | 384 | |
| 385 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 386 | +makeDictEncoder f m r = | |
| 387 | + r | |
| 388 | + |> Dict.toList | |
| 389 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 390 | + |> String.join "," | |
| 391 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 392 | + | |
| 385 | 393 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 386 | 394 | makeNullableEncoder f m = |
| 387 | 395 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -195,7 +195,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 195 | 195 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 196 | 196 | return invalidValue(l(ref || "object"), val, key, parent); |
| 197 | 197 | } |
| 198 | - const result: any = {}; | |
| 198 | + const result: any = Object.create(null); | |
| 199 | 199 | Object.getOwnPropertyNames(props).forEach(key => { |
| 200 | 200 | const prop = props[key]; |
| 201 | 201 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -206,7 +206,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 206 | 206 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 207 | 207 | } |
| 208 | 208 | }); |
| 209 | - return result; | |
| 209 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -162,7 +162,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 162 | 162 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 163 | 163 | return invalidValue(l(ref || "object"), val, key, parent); |
| 164 | 164 | } |
| 165 | - const result: any = {}; | |
| 165 | + const result: any = Object.create(null); | |
| 166 | 166 | Object.getOwnPropertyNames(props).forEach(key => { |
| 167 | 167 | const prop = props[key]; |
| 168 | 168 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -173,7 +173,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 173 | 173 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 174 | 174 | } |
| 175 | 175 | }); |
| 176 | - return result; | |
| 176 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/3536b.json
Melmdefault / QuickType.elm+8 −0
| @@ -183,6 +183,14 @@ encodeText x = | ||
| 183 | 183 | |
| 184 | 184 | --- encoder helpers |
| 185 | 185 | |
| 186 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 187 | +makeDictEncoder f m r = | |
| 188 | + r | |
| 189 | + |> Dict.toList | |
| 190 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 191 | + |> String.join "," | |
| 192 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 193 | + | |
| 186 | 194 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 187 | 195 | makeNullableEncoder f m = |
| 188 | 196 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 143 | 143 | return invalidValue(l(ref || "object"), val, key, parent); |
| 144 | 144 | } |
| 145 | - const result: any = {}; | |
| 145 | + const result: any = Object.create(null); | |
| 146 | 146 | Object.getOwnPropertyNames(props).forEach(key => { |
| 147 | 147 | const prop = props[key]; |
| 148 | 148 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 154 | 154 | } |
| 155 | 155 | }); |
| 156 | - return result; | |
| 156 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/3659d.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/36d5d.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/3a6b3.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/3e9a3.json
Melmdefault / QuickType.elm+8 −0
| @@ -141,6 +141,14 @@ encodeFootnote x = | ||
| 141 | 141 | |
| 142 | 142 | --- encoder helpers |
| 143 | 143 | |
| 144 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 145 | +makeDictEncoder f m r = | |
| 146 | + r | |
| 147 | + |> Dict.toList | |
| 148 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 149 | + |> String.join "," | |
| 150 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 151 | + | |
| 144 | 152 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 145 | 153 | makeNullableEncoder f m = |
| 146 | 154 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 133 | 133 | return invalidValue(l(ref || "object"), val, key, parent); |
| 134 | 134 | } |
| 135 | - const result: any = {}; | |
| 135 | + const result: any = Object.create(null); | |
| 136 | 136 | Object.getOwnPropertyNames(props).forEach(key => { |
| 137 | 137 | const prop = props[key]; |
| 138 | 138 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 144 | 144 | } |
| 145 | 145 | }); |
| 146 | - return result; | |
| 146 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/3f1ce.json
Melmdefault / QuickType.elm+8 −0
| @@ -413,6 +413,14 @@ encodeWind x = | ||
| 413 | 413 | |
| 414 | 414 | --- encoder helpers |
| 415 | 415 | |
| 416 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 417 | +makeDictEncoder f m r = | |
| 418 | + r | |
| 419 | + |> Dict.toList | |
| 420 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 421 | + |> String.join "," | |
| 422 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 423 | + | |
| 416 | 424 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 417 | 425 | makeNullableEncoder f m = |
| 418 | 426 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -208,7 +208,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 208 | 208 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 209 | 209 | return invalidValue(l(ref || "object"), val, key, parent); |
| 210 | 210 | } |
| 211 | - const result: any = {}; | |
| 211 | + const result: any = Object.create(null); | |
| 212 | 212 | Object.getOwnPropertyNames(props).forEach(key => { |
| 213 | 213 | const prop = props[key]; |
| 214 | 214 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -219,7 +219,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 219 | 219 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 220 | 220 | } |
| 221 | 221 | }); |
| 222 | - return result; | |
| 222 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -207,7 +207,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 207 | 207 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 208 | 208 | return invalidValue(l(ref || "object"), val, key, parent); |
| 209 | 209 | } |
| 210 | - const result: any = {}; | |
| 210 | + const result: any = Object.create(null); | |
| 211 | 211 | Object.getOwnPropertyNames(props).forEach(key => { |
| 212 | 212 | const prop = props[key]; |
| 213 | 213 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -218,7 +218,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 218 | 218 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 219 | 219 | } |
| 220 | 220 | }); |
| 221 | - return result; | |
| 221 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/421d4.json
Melmdefault / QuickType.elm+8 −0
| @@ -456,6 +456,14 @@ encodeOwner x = | ||
| 456 | 456 | |
| 457 | 457 | --- encoder helpers |
| 458 | 458 | |
| 459 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 460 | +makeDictEncoder f m r = | |
| 461 | + r | |
| 462 | + |> Dict.toList | |
| 463 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 464 | + |> String.join "," | |
| 465 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 466 | + | |
| 459 | 467 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 460 | 468 | makeNullableEncoder f m = |
| 461 | 469 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -221,7 +221,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 221 | 221 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 222 | 222 | return invalidValue(l(ref || "object"), val, key, parent); |
| 223 | 223 | } |
| 224 | - const result: any = {}; | |
| 224 | + const result: any = Object.create(null); | |
| 225 | 225 | Object.getOwnPropertyNames(props).forEach(key => { |
| 226 | 226 | const prop = props[key]; |
| 227 | 227 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -232,7 +232,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 232 | 232 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 233 | 233 | } |
| 234 | 234 | }); |
| 235 | - return result; | |
| 235 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -218,7 +218,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 218 | 218 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 219 | 219 | return invalidValue(l(ref || "object"), val, key, parent); |
| 220 | 220 | } |
| 221 | - const result: any = {}; | |
| 221 | + const result: any = Object.create(null); | |
| 222 | 222 | Object.getOwnPropertyNames(props).forEach(key => { |
| 223 | 223 | const prop = props[key]; |
| 224 | 224 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -229,7 +229,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 229 | 229 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 230 | 230 | } |
| 231 | 231 | }); |
| 232 | - return result; | |
| 232 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/437e7.json
Melmdefault / QuickType.elm+8 −0
| @@ -429,6 +429,14 @@ encodePagination x = | ||
| 429 | 429 | |
| 430 | 430 | --- encoder helpers |
| 431 | 431 | |
| 432 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 433 | +makeDictEncoder f m r = | |
| 434 | + r | |
| 435 | + |> Dict.toList | |
| 436 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 437 | + |> String.join "," | |
| 438 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 439 | + | |
| 432 | 440 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 433 | 441 | makeNullableEncoder f m = |
| 434 | 442 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 217 | 217 | return invalidValue(l(ref || "object"), val, key, parent); |
| 218 | 218 | } |
| 219 | - const result: any = {}; | |
| 219 | + const result: any = Object.create(null); | |
| 220 | 220 | Object.getOwnPropertyNames(props).forEach(key => { |
| 221 | 221 | const prop = props[key]; |
| 222 | 222 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -227,7 +227,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 227 | 227 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 228 | 228 | } |
| 229 | 229 | }); |
| 230 | - return result; | |
| 230 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -211,7 +211,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 211 | 211 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 212 | 212 | return invalidValue(l(ref || "object"), val, key, parent); |
| 213 | 213 | } |
| 214 | - const result: any = {}; | |
| 214 | + const result: any = Object.create(null); | |
| 215 | 215 | Object.getOwnPropertyNames(props).forEach(key => { |
| 216 | 216 | const prop = props[key]; |
| 217 | 217 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -222,7 +222,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 222 | 222 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 223 | 223 | } |
| 224 | 224 | }); |
| 225 | - return result; | |
| 225 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/43970.json
Melmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickTypeElement x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/43eaf.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/458db.json
Melmdefault / QuickType.elm+8 −0
| @@ -204,6 +204,14 @@ encodeName x = case x of | ||
| 204 | 204 | |
| 205 | 205 | --- encoder helpers |
| 206 | 206 | |
| 207 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 208 | +makeDictEncoder f m r = | |
| 209 | + r | |
| 210 | + |> Dict.toList | |
| 211 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 212 | + |> String.join "," | |
| 213 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 214 | + | |
| 207 | 215 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 208 | 216 | makeNullableEncoder f m = |
| 209 | 217 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 150 | 150 | return invalidValue(l(ref || "object"), val, key, parent); |
| 151 | 151 | } |
| 152 | - const result: any = {}; | |
| 152 | + const result: any = Object.create(null); | |
| 153 | 153 | Object.getOwnPropertyNames(props).forEach(key => { |
| 154 | 154 | const prop = props[key]; |
| 155 | 155 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -160,7 +160,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 160 | 160 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 161 | 161 | } |
| 162 | 162 | }); |
| 163 | - return result; | |
| 163 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -148,7 +148,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 148 | 148 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 149 | 149 | return invalidValue(l(ref || "object"), val, key, parent); |
| 150 | 150 | } |
| 151 | - const result: any = {}; | |
| 151 | + const result: any = Object.create(null); | |
| 152 | 152 | Object.getOwnPropertyNames(props).forEach(key => { |
| 153 | 153 | const prop = props[key]; |
| 154 | 154 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -159,7 +159,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 159 | 159 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 160 | 160 | } |
| 161 | 161 | }); |
| 162 | - return result; | |
| 162 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/4961a.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/4a0d7.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/4a455.json
Melmdefault / QuickType.elm+8 −0
| @@ -223,6 +223,14 @@ encodeFeatureProperties x = | ||
| 223 | 223 | |
| 224 | 224 | --- encoder helpers |
| 225 | 225 | |
| 226 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 227 | +makeDictEncoder f m r = | |
| 228 | + r | |
| 229 | + |> Dict.toList | |
| 230 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 231 | + |> String.join "," | |
| 232 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 233 | + | |
| 226 | 234 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 227 | 235 | makeNullableEncoder f m = |
| 228 | 236 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -150,7 +150,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 150 | 150 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 151 | 151 | return invalidValue(l(ref || "object"), val, key, parent); |
| 152 | 152 | } |
| 153 | - const result: any = {}; | |
| 153 | + const result: any = Object.create(null); | |
| 154 | 154 | Object.getOwnPropertyNames(props).forEach(key => { |
| 155 | 155 | const prop = props[key]; |
| 156 | 156 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -161,7 +161,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 161 | 161 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 162 | 162 | } |
| 163 | 163 | }); |
| 164 | - return result; | |
| 164 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/4c547.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/4d6fb.json
Melmdefault / QuickType.elm+8 −0
| @@ -584,6 +584,14 @@ encodeKind x = case x of | ||
| 584 | 584 | |
| 585 | 585 | --- encoder helpers |
| 586 | 586 | |
| 587 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 588 | +makeDictEncoder f m r = | |
| 589 | + r | |
| 590 | + |> Dict.toList | |
| 591 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 592 | + |> String.join "," | |
| 593 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 594 | + | |
| 587 | 595 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 588 | 596 | makeNullableEncoder f m = |
| 589 | 597 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -255,7 +255,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 255 | 255 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 256 | 256 | return invalidValue(l(ref || "object"), val, key, parent); |
| 257 | 257 | } |
| 258 | - const result: any = {}; | |
| 258 | + const result: any = Object.create(null); | |
| 259 | 259 | Object.getOwnPropertyNames(props).forEach(key => { |
| 260 | 260 | const prop = props[key]; |
| 261 | 261 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -266,7 +266,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 266 | 266 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 267 | 267 | } |
| 268 | 268 | }); |
| 269 | - return result; | |
| 269 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -245,7 +245,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 245 | 245 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 246 | 246 | return invalidValue(l(ref || "object"), val, key, parent); |
| 247 | 247 | } |
| 248 | - const result: any = {}; | |
| 248 | + const result: any = Object.create(null); | |
| 249 | 249 | Object.getOwnPropertyNames(props).forEach(key => { |
| 250 | 250 | const prop = props[key]; |
| 251 | 251 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -256,7 +256,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 256 | 256 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 257 | 257 | } |
| 258 | 258 | }); |
| 259 | - return result; | |
| 259 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/4e336.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/54147.json
Melmdefault / QuickType.elm+8 −0
| @@ -108,6 +108,14 @@ encodeHeaders x = | ||
| 108 | 108 | |
| 109 | 109 | --- encoder helpers |
| 110 | 110 | |
| 111 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 112 | +makeDictEncoder f m r = | |
| 113 | + r | |
| 114 | + |> Dict.toList | |
| 115 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 116 | + |> String.join "," | |
| 117 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 118 | + | |
| 111 | 119 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 112 | 120 | makeNullableEncoder f m = |
| 113 | 121 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 124 | 124 | return invalidValue(l(ref || "object"), val, key, parent); |
| 125 | 125 | } |
| 126 | - const result: any = {}; | |
| 126 | + const result: any = Object.create(null); | |
| 127 | 127 | Object.getOwnPropertyNames(props).forEach(key => { |
| 128 | 128 | const prop = props[key]; |
| 129 | 129 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 135 | 135 | } |
| 136 | 136 | }); |
| 137 | - return result; | |
| 137 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/54d32.json
Melmdefault / QuickType.elm+8 −0
| @@ -134,6 +134,14 @@ encodeStatus x = case x of | ||
| 134 | 134 | |
| 135 | 135 | --- encoder helpers |
| 136 | 136 | |
| 137 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 138 | +makeDictEncoder f m r = | |
| 139 | + r | |
| 140 | + |> Dict.toList | |
| 141 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 142 | + |> String.join "," | |
| 143 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 144 | + | |
| 137 | 145 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 138 | 146 | makeNullableEncoder f m = |
| 139 | 147 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 130 | 130 | return invalidValue(l(ref || "object"), val, key, parent); |
| 131 | 131 | } |
| 132 | - const result: any = {}; | |
| 132 | + const result: any = Object.create(null); | |
| 133 | 133 | Object.getOwnPropertyNames(props).forEach(key => { |
| 134 | 134 | const prop = props[key]; |
| 135 | 135 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 141 | 141 | } |
| 142 | 142 | }); |
| 143 | - return result; | |
| 143 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 125 | 125 | return invalidValue(l(ref || "object"), val, key, parent); |
| 126 | 126 | } |
| 127 | - const result: any = {}; | |
| 127 | + const result: any = Object.create(null); | |
| 128 | 128 | Object.getOwnPropertyNames(props).forEach(key => { |
| 129 | 129 | const prop = props[key]; |
| 130 | 130 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 136 | 136 | } |
| 137 | 137 | }); |
| 138 | - return result; | |
| 138 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/570ec.json
Melmdefault / QuickType.elm+8 −0
| @@ -179,6 +179,14 @@ encodeText x = | ||
| 179 | 179 | |
| 180 | 180 | --- encoder helpers |
| 181 | 181 | |
| 182 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 183 | +makeDictEncoder f m r = | |
| 184 | + r | |
| 185 | + |> Dict.toList | |
| 186 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 187 | + |> String.join "," | |
| 188 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 189 | + | |
| 182 | 190 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 183 | 191 | makeNullableEncoder f m = |
| 184 | 192 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 143 | 143 | return invalidValue(l(ref || "object"), val, key, parent); |
| 144 | 144 | } |
| 145 | - const result: any = {}; | |
| 145 | + const result: any = Object.create(null); | |
| 146 | 146 | Object.getOwnPropertyNames(props).forEach(key => { |
| 147 | 147 | const prop = props[key]; |
| 148 | 148 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 154 | 154 | } |
| 155 | 155 | }); |
| 156 | - return result; | |
| 156 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 140 | 140 | return invalidValue(l(ref || "object"), val, key, parent); |
| 141 | 141 | } |
| 142 | - const result: any = {}; | |
| 142 | + const result: any = Object.create(null); | |
| 143 | 143 | Object.getOwnPropertyNames(props).forEach(key => { |
| 144 | 144 | const prop = props[key]; |
| 145 | 145 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -150,7 +150,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 150 | 150 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 151 | 151 | } |
| 152 | 152 | }); |
| 153 | - return result; | |
| 153 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/5dd0d.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/5eae5.json
Melmdefault / QuickType.elm+8 −0
| @@ -65,6 +65,14 @@ encodeQuickTypeElement x = | ||
| 65 | 65 | |
| 66 | 66 | --- encoder helpers |
| 67 | 67 | |
| 68 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 69 | +makeDictEncoder f m r = | |
| 70 | + r | |
| 71 | + |> Dict.toList | |
| 72 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 73 | + |> String.join "," | |
| 74 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 75 | + | |
| 68 | 76 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 69 | 77 | makeNullableEncoder f m = |
| 70 | 78 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/5eb20.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/5f3a1.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/5f7fe.json
Melmdefault / QuickType.elm+8 −0
| @@ -728,6 +728,14 @@ encodeExpression x = | ||
| 728 | 728 | |
| 729 | 729 | --- encoder helpers |
| 730 | 730 | |
| 731 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 732 | +makeDictEncoder f m r = | |
| 733 | + r | |
| 734 | + |> Dict.toList | |
| 735 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 736 | + |> String.join "," | |
| 737 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 738 | + | |
| 731 | 739 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 732 | 740 | makeNullableEncoder f m = |
| 733 | 741 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -295,7 +295,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 295 | 295 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 296 | 296 | return invalidValue(l(ref || "object"), val, key, parent); |
| 297 | 297 | } |
| 298 | - const result: any = {}; | |
| 298 | + const result: any = Object.create(null); | |
| 299 | 299 | Object.getOwnPropertyNames(props).forEach(key => { |
| 300 | 300 | const prop = props[key]; |
| 301 | 301 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -306,7 +306,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 306 | 306 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 307 | 307 | } |
| 308 | 308 | }); |
| 309 | - return result; | |
| 309 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -292,7 +292,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 292 | 292 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 293 | 293 | return invalidValue(l(ref || "object"), val, key, parent); |
| 294 | 294 | } |
| 295 | - const result: any = {}; | |
| 295 | + const result: any = Object.create(null); | |
| 296 | 296 | Object.getOwnPropertyNames(props).forEach(key => { |
| 297 | 297 | const prop = props[key]; |
| 298 | 298 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -303,7 +303,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 303 | 303 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 304 | 304 | } |
| 305 | 305 | }); |
| 306 | - return result; | |
| 306 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/617e8.json
Melmdefault / QuickType.elm+8 −0
| @@ -725,6 +725,14 @@ encodeExpression x = | ||
| 725 | 725 | |
| 726 | 726 | --- encoder helpers |
| 727 | 727 | |
| 728 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 729 | +makeDictEncoder f m r = | |
| 730 | + r | |
| 731 | + |> Dict.toList | |
| 732 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 733 | + |> String.join "," | |
| 734 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 735 | + | |
| 728 | 736 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 729 | 737 | makeNullableEncoder f m = |
| 730 | 738 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -294,7 +294,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 294 | 294 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 295 | 295 | return invalidValue(l(ref || "object"), val, key, parent); |
| 296 | 296 | } |
| 297 | - const result: any = {}; | |
| 297 | + const result: any = Object.create(null); | |
| 298 | 298 | Object.getOwnPropertyNames(props).forEach(key => { |
| 299 | 299 | const prop = props[key]; |
| 300 | 300 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -305,7 +305,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 305 | 305 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 306 | 306 | } |
| 307 | 307 | }); |
| 308 | - return result; | |
| 308 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -291,7 +291,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 291 | 291 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 292 | 292 | return invalidValue(l(ref || "object"), val, key, parent); |
| 293 | 293 | } |
| 294 | - const result: any = {}; | |
| 294 | + const result: any = Object.create(null); | |
| 295 | 295 | Object.getOwnPropertyNames(props).forEach(key => { |
| 296 | 296 | const prop = props[key]; |
| 297 | 297 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -302,7 +302,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 302 | 302 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 303 | 303 | } |
| 304 | 304 | }); |
| 305 | - return result; | |
| 305 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/61b66.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/6260a.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/65dec.json
Melmdefault / QuickType.elm+8 −0
| @@ -371,6 +371,14 @@ encodeType x = case x of | ||
| 371 | 371 | |
| 372 | 372 | --- encoder helpers |
| 373 | 373 | |
| 374 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 375 | +makeDictEncoder f m r = | |
| 376 | + r | |
| 377 | + |> Dict.toList | |
| 378 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 379 | + |> String.join "," | |
| 380 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 381 | + | |
| 374 | 382 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 375 | 383 | makeNullableEncoder f m = |
| 376 | 384 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -194,7 +194,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 194 | 194 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 195 | 195 | return invalidValue(l(ref || "object"), val, key, parent); |
| 196 | 196 | } |
| 197 | - const result: any = {}; | |
| 197 | + const result: any = Object.create(null); | |
| 198 | 198 | Object.getOwnPropertyNames(props).forEach(key => { |
| 199 | 199 | const prop = props[key]; |
| 200 | 200 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 206 | 206 | } |
| 207 | 207 | }); |
| 208 | - return result; | |
| 208 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -170,7 +170,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 170 | 170 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 171 | 171 | return invalidValue(l(ref || "object"), val, key, parent); |
| 172 | 172 | } |
| 173 | - const result: any = {}; | |
| 173 | + const result: any = Object.create(null); | |
| 174 | 174 | Object.getOwnPropertyNames(props).forEach(key => { |
| 175 | 175 | const prop = props[key]; |
| 176 | 176 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -181,7 +181,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 181 | 181 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 182 | 182 | } |
| 183 | 183 | }); |
| 184 | - return result; | |
| 184 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/66121.json
Melmdefault / QuickType.elm+8 −0
| @@ -234,6 +234,14 @@ encodeTitle x = case x of | ||
| 234 | 234 | |
| 235 | 235 | --- encoder helpers |
| 236 | 236 | |
| 237 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 238 | +makeDictEncoder f m r = | |
| 239 | + r | |
| 240 | + |> Dict.toList | |
| 241 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 242 | + |> String.join "," | |
| 243 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 244 | + | |
| 237 | 245 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 238 | 246 | makeNullableEncoder f m = |
| 239 | 247 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 152 | 152 | return invalidValue(l(ref || "object"), val, key, parent); |
| 153 | 153 | } |
| 154 | - const result: any = {}; | |
| 154 | + const result: any = Object.create(null); | |
| 155 | 155 | Object.getOwnPropertyNames(props).forEach(key => { |
| 156 | 156 | const prop = props[key]; |
| 157 | 157 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -162,7 +162,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 162 | 162 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 163 | 163 | } |
| 164 | 164 | }); |
| 165 | - return result; | |
| 165 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 143 | 143 | return invalidValue(l(ref || "object"), val, key, parent); |
| 144 | 144 | } |
| 145 | - const result: any = {}; | |
| 145 | + const result: any = Object.create(null); | |
| 146 | 146 | Object.getOwnPropertyNames(props).forEach(key => { |
| 147 | 147 | const prop = props[key]; |
| 148 | 148 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 154 | 154 | } |
| 155 | 155 | }); |
| 156 | - return result; | |
| 156 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/6617c.json
Melmdefault / QuickType.elm+8 −0
| @@ -75,6 +75,14 @@ encodeIssPosition x = | ||
| 75 | 75 | |
| 76 | 76 | --- encoder helpers |
| 77 | 77 | |
| 78 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 79 | +makeDictEncoder f m r = | |
| 80 | + r | |
| 81 | + |> Dict.toList | |
| 82 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 83 | + |> String.join "," | |
| 84 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 85 | + | |
| 78 | 86 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 79 | 87 | makeNullableEncoder f m = |
| 80 | 88 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/67c03.json
Melmdefault / QuickType.elm+8 −0
| @@ -75,6 +75,14 @@ encodePerson x = | ||
| 75 | 75 | |
| 76 | 76 | --- encoder helpers |
| 77 | 77 | |
| 78 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 79 | +makeDictEncoder f m r = | |
| 80 | + r | |
| 81 | + |> Dict.toList | |
| 82 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 83 | + |> String.join "," | |
| 84 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 85 | + | |
| 78 | 86 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 79 | 87 | makeNullableEncoder f m = |
| 80 | 88 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/68c30.json
Melmdefault / QuickType.elm+8 −0
| @@ -155,6 +155,14 @@ encodeOut x = | ||
| 155 | 155 | |
| 156 | 156 | --- encoder helpers |
| 157 | 157 | |
| 158 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 159 | +makeDictEncoder f m r = | |
| 160 | + r | |
| 161 | + |> Dict.toList | |
| 162 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 163 | + |> String.join "," | |
| 164 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 165 | + | |
| 158 | 166 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 159 | 167 | makeNullableEncoder f m = |
| 160 | 168 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 139 | 139 | return invalidValue(l(ref || "object"), val, key, parent); |
| 140 | 140 | } |
| 141 | - const result: any = {}; | |
| 141 | + const result: any = Object.create(null); | |
| 142 | 142 | Object.getOwnPropertyNames(props).forEach(key => { |
| 143 | 143 | const prop = props[key]; |
| 144 | 144 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 150 | 150 | } |
| 151 | 151 | }); |
| 152 | - return result; | |
| 152 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 139 | 139 | return invalidValue(l(ref || "object"), val, key, parent); |
| 140 | 140 | } |
| 141 | - const result: any = {}; | |
| 141 | + const result: any = Object.create(null); | |
| 142 | 142 | Object.getOwnPropertyNames(props).forEach(key => { |
| 143 | 143 | const prop = props[key]; |
| 144 | 144 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 150 | 150 | } |
| 151 | 151 | }); |
| 152 | - return result; | |
| 152 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/6c155.json
Melmdefault / QuickType.elm+8 −0
| @@ -233,6 +233,14 @@ encodeLocation x = | ||
| 233 | 233 | |
| 234 | 234 | --- encoder helpers |
| 235 | 235 | |
| 236 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 237 | +makeDictEncoder f m r = | |
| 238 | + r | |
| 239 | + |> Dict.toList | |
| 240 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 241 | + |> String.join "," | |
| 242 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 243 | + | |
| 236 | 244 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 237 | 245 | makeNullableEncoder f m = |
| 238 | 246 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -160,7 +160,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 160 | 160 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 161 | 161 | return invalidValue(l(ref || "object"), val, key, parent); |
| 162 | 162 | } |
| 163 | - const result: any = {}; | |
| 163 | + const result: any = Object.create(null); | |
| 164 | 164 | Object.getOwnPropertyNames(props).forEach(key => { |
| 165 | 165 | const prop = props[key]; |
| 166 | 166 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -171,7 +171,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 171 | 171 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 172 | 172 | } |
| 173 | 173 | }); |
| 174 | - return result; | |
| 174 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -160,7 +160,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 160 | 160 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 161 | 161 | return invalidValue(l(ref || "object"), val, key, parent); |
| 162 | 162 | } |
| 163 | - const result: any = {}; | |
| 163 | + const result: any = Object.create(null); | |
| 164 | 164 | Object.getOwnPropertyNames(props).forEach(key => { |
| 165 | 165 | const prop = props[key]; |
| 166 | 166 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -171,7 +171,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 171 | 171 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 172 | 172 | } |
| 173 | 173 | }); |
| 174 | - return result; | |
| 174 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/6de06.json
Melmdefault / QuickType.elm+8 −0
| @@ -562,6 +562,14 @@ encodeKind x = case x of | ||
| 562 | 562 | |
| 563 | 563 | --- encoder helpers |
| 564 | 564 | |
| 565 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 566 | +makeDictEncoder f m r = | |
| 567 | + r | |
| 568 | + |> Dict.toList | |
| 569 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 570 | + |> String.join "," | |
| 571 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 572 | + | |
| 565 | 573 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 566 | 574 | makeNullableEncoder f m = |
| 567 | 575 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -255,7 +255,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 255 | 255 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 256 | 256 | return invalidValue(l(ref || "object"), val, key, parent); |
| 257 | 257 | } |
| 258 | - const result: any = {}; | |
| 258 | + const result: any = Object.create(null); | |
| 259 | 259 | Object.getOwnPropertyNames(props).forEach(key => { |
| 260 | 260 | const prop = props[key]; |
| 261 | 261 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -266,7 +266,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 266 | 266 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 267 | 267 | } |
| 268 | 268 | }); |
| 269 | - return result; | |
| 269 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -250,7 +250,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 250 | 250 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 251 | 251 | return invalidValue(l(ref || "object"), val, key, parent); |
| 252 | 252 | } |
| 253 | - const result: any = {}; | |
| 253 | + const result: any = Object.create(null); | |
| 254 | 254 | Object.getOwnPropertyNames(props).forEach(key => { |
| 255 | 255 | const prop = props[key]; |
| 256 | 256 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -261,7 +261,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 261 | 261 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 262 | 262 | } |
| 263 | 263 | }); |
| 264 | - return result; | |
| 264 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/6dec6.json
Melmdefault / QuickType.elm+8 −0
| @@ -419,6 +419,14 @@ encodeWind x = | ||
| 419 | 419 | |
| 420 | 420 | --- encoder helpers |
| 421 | 421 | |
| 422 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 423 | +makeDictEncoder f m r = | |
| 424 | + r | |
| 425 | + |> Dict.toList | |
| 426 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 427 | + |> String.join "," | |
| 428 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 429 | + | |
| 422 | 430 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 423 | 431 | makeNullableEncoder f m = |
| 424 | 432 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -210,7 +210,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 210 | 210 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 211 | 211 | return invalidValue(l(ref || "object"), val, key, parent); |
| 212 | 212 | } |
| 213 | - const result: any = {}; | |
| 213 | + const result: any = Object.create(null); | |
| 214 | 214 | Object.getOwnPropertyNames(props).forEach(key => { |
| 215 | 215 | const prop = props[key]; |
| 216 | 216 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -221,7 +221,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 221 | 221 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 222 | 222 | } |
| 223 | 223 | }); |
| 224 | - return result; | |
| 224 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -207,7 +207,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 207 | 207 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 208 | 208 | return invalidValue(l(ref || "object"), val, key, parent); |
| 209 | 209 | } |
| 210 | - const result: any = {}; | |
| 210 | + const result: any = Object.create(null); | |
| 211 | 211 | Object.getOwnPropertyNames(props).forEach(key => { |
| 212 | 212 | const prop = props[key]; |
| 213 | 213 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -218,7 +218,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 218 | 218 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 219 | 219 | } |
| 220 | 220 | }); |
| 221 | - return result; | |
| 221 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/6eb00.json
Melmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickTypeElement x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/70c77.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/734ad.json
Melmdefault / QuickType.elm+8 −0
| @@ -290,6 +290,14 @@ encodeStatus x = case x of | ||
| 290 | 290 | |
| 291 | 291 | --- encoder helpers |
| 292 | 292 | |
| 293 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 294 | +makeDictEncoder f m r = | |
| 295 | + r | |
| 296 | + |> Dict.toList | |
| 297 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 298 | + |> String.join "," | |
| 299 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 300 | + | |
| 293 | 301 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 294 | 302 | makeNullableEncoder f m = |
| 295 | 303 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -181,7 +181,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 181 | 181 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 182 | 182 | return invalidValue(l(ref || "object"), val, key, parent); |
| 183 | 183 | } |
| 184 | - const result: any = {}; | |
| 184 | + const result: any = Object.create(null); | |
| 185 | 185 | Object.getOwnPropertyNames(props).forEach(key => { |
| 186 | 186 | const prop = props[key]; |
| 187 | 187 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -192,7 +192,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 192 | 192 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 193 | 193 | } |
| 194 | 194 | }); |
| 195 | - return result; | |
| 195 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -176,7 +176,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 176 | 176 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 177 | 177 | return invalidValue(l(ref || "object"), val, key, parent); |
| 178 | 178 | } |
| 179 | - const result: any = {}; | |
| 179 | + const result: any = Object.create(null); | |
| 180 | 180 | Object.getOwnPropertyNames(props).forEach(key => { |
| 181 | 181 | const prop = props[key]; |
| 182 | 182 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -187,7 +187,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 187 | 187 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 188 | 188 | } |
| 189 | 189 | }); |
| 190 | - return result; | |
| 190 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/75912.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/7681c.json
Melmdefault / QuickType.elm+8 −0
| @@ -458,6 +458,14 @@ encodePagination x = | ||
| 458 | 458 | |
| 459 | 459 | --- encoder helpers |
| 460 | 460 | |
| 461 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 462 | +makeDictEncoder f m r = | |
| 463 | + r | |
| 464 | + |> Dict.toList | |
| 465 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 466 | + |> String.join "," | |
| 467 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 468 | + | |
| 461 | 469 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 462 | 470 | makeNullableEncoder f m = |
| 463 | 471 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -223,7 +223,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 223 | 223 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 224 | 224 | return invalidValue(l(ref || "object"), val, key, parent); |
| 225 | 225 | } |
| 226 | - const result: any = {}; | |
| 226 | + const result: any = Object.create(null); | |
| 227 | 227 | Object.getOwnPropertyNames(props).forEach(key => { |
| 228 | 228 | const prop = props[key]; |
| 229 | 229 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -234,7 +234,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 234 | 234 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 235 | 235 | } |
| 236 | 236 | }); |
| 237 | - return result; | |
| 237 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -215,7 +215,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 215 | 215 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 216 | 216 | return invalidValue(l(ref || "object"), val, key, parent); |
| 217 | 217 | } |
| 218 | - const result: any = {}; | |
| 218 | + const result: any = Object.create(null); | |
| 219 | 219 | Object.getOwnPropertyNames(props).forEach(key => { |
| 220 | 220 | const prop = props[key]; |
| 221 | 221 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 227 | 227 | } |
| 228 | 228 | }); |
| 229 | - return result; | |
| 229 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/76ae1.json
Melmdefault / QuickType.elm+9 −1
| @@ -316,7 +316,7 @@ article = | ||
| 316 | 316 | encodeArticle : Article -> Jenc.Value |
| 317 | 317 | encodeArticle x = |
| 318 | 318 | Jenc.object |
| 319 | - [ ("properties", Jenc.dict identity encodeProperty x.properties) | |
| 319 | + [ ("properties", makeDictEncoder identity encodeProperty x.properties) | |
| 320 | 320 | ] |
| 321 | 321 | |
| 322 | 322 | property : Jdec.Decoder Property |
| @@ -722,6 +722,14 @@ encodeSchemaType x = case x of | ||
| 722 | 722 | |
| 723 | 723 | --- encoder helpers |
| 724 | 724 | |
| 725 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 726 | +makeDictEncoder f m r = | |
| 727 | + r | |
| 728 | + |> Dict.toList | |
| 729 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 730 | + |> String.join "," | |
| 731 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 732 | + | |
| 725 | 733 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 726 | 734 | makeNullableEncoder f m = |
| 727 | 735 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -291,7 +291,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 291 | 291 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 292 | 292 | return invalidValue(l(ref || "object"), val, key, parent); |
| 293 | 293 | } |
| 294 | - const result: any = {}; | |
| 294 | + const result: any = Object.create(null); | |
| 295 | 295 | Object.getOwnPropertyNames(props).forEach(key => { |
| 296 | 296 | const prop = props[key]; |
| 297 | 297 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -302,7 +302,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 302 | 302 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 303 | 303 | } |
| 304 | 304 | }); |
| 305 | - return result; | |
| 305 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -288,7 +288,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 288 | 288 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 289 | 289 | return invalidValue(l(ref || "object"), val, key, parent); |
| 290 | 290 | } |
| 291 | - const result: any = {}; | |
| 291 | + const result: any = Object.create(null); | |
| 292 | 292 | Object.getOwnPropertyNames(props).forEach(key => { |
| 293 | 293 | const prop = props[key]; |
| 294 | 294 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -299,7 +299,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 299 | 299 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 300 | 300 | } |
| 301 | 301 | }); |
| 302 | - return result; | |
| 302 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/77392.json
Melmdefault / QuickType.elm+8 −0
| @@ -147,6 +147,14 @@ encodePha x = case x of | ||
| 147 | 147 | |
| 148 | 148 | --- encoder helpers |
| 149 | 149 | |
| 150 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 151 | +makeDictEncoder f m r = | |
| 152 | + r | |
| 153 | + |> Dict.toList | |
| 154 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 155 | + |> String.join "," | |
| 156 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 157 | + | |
| 150 | 158 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 151 | 159 | makeNullableEncoder f m = |
| 152 | 160 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 135 | 135 | return invalidValue(l(ref || "object"), val, key, parent); |
| 136 | 136 | } |
| 137 | - const result: any = {}; | |
| 137 | + const result: any = Object.create(null); | |
| 138 | 138 | Object.getOwnPropertyNames(props).forEach(key => { |
| 139 | 139 | const prop = props[key]; |
| 140 | 140 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -145,7 +145,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 145 | 145 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 146 | 146 | } |
| 147 | 147 | }); |
| 148 | - return result; | |
| 148 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 123 | 123 | return invalidValue(l(ref || "object"), val, key, parent); |
| 124 | 124 | } |
| 125 | - const result: any = {}; | |
| 125 | + const result: any = Object.create(null); | |
| 126 | 126 | Object.getOwnPropertyNames(props).forEach(key => { |
| 127 | 127 | const prop = props[key]; |
| 128 | 128 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 134 | 134 | } |
| 135 | 135 | }); |
| 136 | - return result; | |
| 136 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/7d397.json
Melmdefault / QuickType.elm+9 −1
| @@ -170,7 +170,7 @@ listClass = | ||
| 170 | 170 | encodeListClass : ListClass -> Jenc.Value |
| 171 | 171 | encodeListClass x = |
| 172 | 172 | Jenc.object |
| 173 | - [ ("properties", Jenc.dict identity encodeProperty x.properties) | |
| 173 | + [ ("properties", makeDictEncoder identity encodeProperty x.properties) | |
| 174 | 174 | ] |
| 175 | 175 | |
| 176 | 176 | property : Jdec.Decoder Property |
| @@ -339,6 +339,14 @@ encodeItems x = | ||
| 339 | 339 | |
| 340 | 340 | --- encoder helpers |
| 341 | 341 | |
| 342 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 343 | +makeDictEncoder f m r = | |
| 344 | + r | |
| 345 | + |> Dict.toList | |
| 346 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 347 | + |> String.join "," | |
| 348 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 349 | + | |
| 342 | 350 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 343 | 351 | makeNullableEncoder f m = |
| 344 | 352 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -182,7 +182,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 182 | 182 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 183 | 183 | return invalidValue(l(ref || "object"), val, key, parent); |
| 184 | 184 | } |
| 185 | - const result: any = {}; | |
| 185 | + const result: any = Object.create(null); | |
| 186 | 186 | Object.getOwnPropertyNames(props).forEach(key => { |
| 187 | 187 | const prop = props[key]; |
| 188 | 188 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -193,7 +193,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 193 | 193 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 194 | 194 | } |
| 195 | 195 | }); |
| 196 | - return result; | |
| 196 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -180,7 +180,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 180 | 180 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 181 | 181 | return invalidValue(l(ref || "object"), val, key, parent); |
| 182 | 182 | } |
| 183 | - const result: any = {}; | |
| 183 | + const result: any = Object.create(null); | |
| 184 | 184 | Object.getOwnPropertyNames(props).forEach(key => { |
| 185 | 185 | const prop = props[key]; |
| 186 | 186 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -191,7 +191,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 191 | 191 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 192 | 192 | } |
| 193 | 193 | }); |
| 194 | - return result; | |
| 194 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/7d722.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/7df41.json
Melmdefault / QuickType.elm+8 −0
| @@ -84,6 +84,14 @@ encodePC x = | ||
| 84 | 84 | |
| 85 | 85 | --- encoder helpers |
| 86 | 86 | |
| 87 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 88 | +makeDictEncoder f m r = | |
| 89 | + r | |
| 90 | + |> Dict.toList | |
| 91 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 92 | + |> String.join "," | |
| 93 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 94 | + | |
| 87 | 95 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 88 | 96 | makeNullableEncoder f m = |
| 89 | 97 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/7dfa6.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/7eb30.json
Melmdefault / QuickType.elm+8 −0
| @@ -230,6 +230,14 @@ encodeTelEnum x = case x of | ||
| 230 | 230 | |
| 231 | 231 | --- encoder helpers |
| 232 | 232 | |
| 233 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 234 | +makeDictEncoder f m r = | |
| 235 | + r | |
| 236 | + |> Dict.toList | |
| 237 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 238 | + |> String.join "," | |
| 239 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 240 | + | |
| 233 | 241 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 234 | 242 | makeNullableEncoder f m = |
| 235 | 243 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 152 | 152 | return invalidValue(l(ref || "object"), val, key, parent); |
| 153 | 153 | } |
| 154 | - const result: any = {}; | |
| 154 | + const result: any = Object.create(null); | |
| 155 | 155 | Object.getOwnPropertyNames(props).forEach(key => { |
| 156 | 156 | const prop = props[key]; |
| 157 | 157 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -162,7 +162,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 162 | 162 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 163 | 163 | } |
| 164 | 164 | }); |
| 165 | - return result; | |
| 165 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -144,7 +144,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 144 | 144 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 145 | 145 | return invalidValue(l(ref || "object"), val, key, parent); |
| 146 | 146 | } |
| 147 | - const result: any = {}; | |
| 147 | + const result: any = Object.create(null); | |
| 148 | 148 | Object.getOwnPropertyNames(props).forEach(key => { |
| 149 | 149 | const prop = props[key]; |
| 150 | 150 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -155,7 +155,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 155 | 155 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 156 | 156 | } |
| 157 | 157 | }); |
| 158 | - return result; | |
| 158 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/7f568.json
Melmdefault / QuickType.elm+9 −1
| @@ -103,7 +103,7 @@ encodeQuickTypeElement x = | ||
| 103 | 103 | , ("commits_url", Jenc.string x.commitsURL) |
| 104 | 104 | , ("created_at", Jenc.string x.createdAt) |
| 105 | 105 | , ("description", makeNullableEncoder Jenc.string x.description) |
| 106 | - , ("files", Jenc.dict identity encodeFile x.files) | |
| 106 | + , ("files", makeDictEncoder identity encodeFile x.files) | |
| 107 | 107 | , ("forks_url", Jenc.string x.forksURL) |
| 108 | 108 | , ("git_pull_url", Jenc.string x.gitPullURL) |
| 109 | 109 | , ("git_push_url", Jenc.string x.gitPushURL) |
| @@ -163,6 +163,14 @@ encodeLanguage x = case x of | ||
| 163 | 163 | |
| 164 | 164 | --- encoder helpers |
| 165 | 165 | |
| 166 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 167 | +makeDictEncoder f m r = | |
| 168 | + r | |
| 169 | + |> Dict.toList | |
| 170 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 171 | + |> String.join "," | |
| 172 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 173 | + | |
| 166 | 174 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 167 | 175 | makeNullableEncoder f m = |
| 168 | 176 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 139 | 139 | return invalidValue(l(ref || "object"), val, key, parent); |
| 140 | 140 | } |
| 141 | - const result: any = {}; | |
| 141 | + const result: any = Object.create(null); | |
| 142 | 142 | Object.getOwnPropertyNames(props).forEach(key => { |
| 143 | 143 | const prop = props[key]; |
| 144 | 144 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 150 | 150 | } |
| 151 | 151 | }); |
| 152 | - return result; | |
| 152 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/7fbfb.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeFluffyQuickType x = | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/80aff.json
Melmdefault / QuickType.elm+8 −0
| @@ -117,6 +117,14 @@ encodeResult x = | ||
| 117 | 117 | |
| 118 | 118 | --- encoder helpers |
| 119 | 119 | |
| 120 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 121 | +makeDictEncoder f m r = | |
| 122 | + r | |
| 123 | + |> Dict.toList | |
| 124 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 125 | + |> String.join "," | |
| 126 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 127 | + | |
| 120 | 128 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 121 | 129 | makeNullableEncoder f m = |
| 122 | 130 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 127 | 127 | return invalidValue(l(ref || "object"), val, key, parent); |
| 128 | 128 | } |
| 129 | - const result: any = {}; | |
| 129 | + const result: any = Object.create(null); | |
| 130 | 130 | Object.getOwnPropertyNames(props).forEach(key => { |
| 131 | 131 | const prop = props[key]; |
| 132 | 132 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -137,7 +137,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 137 | 137 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 138 | 138 | } |
| 139 | 139 | }); |
| 140 | - return result; | |
| 140 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 124 | 124 | return invalidValue(l(ref || "object"), val, key, parent); |
| 125 | 125 | } |
| 126 | - const result: any = {}; | |
| 126 | + const result: any = Object.create(null); | |
| 127 | 127 | Object.getOwnPropertyNames(props).forEach(key => { |
| 128 | 128 | const prop = props[key]; |
| 129 | 129 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 135 | 135 | } |
| 136 | 136 | }); |
| 137 | - return result; | |
| 137 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/82509.json
Melmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/8592b.json
Melmdefault / QuickType.elm+8 −0
| @@ -505,6 +505,14 @@ encodeKind x = case x of | ||
| 505 | 505 | |
| 506 | 506 | --- encoder helpers |
| 507 | 507 | |
| 508 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 509 | +makeDictEncoder f m r = | |
| 510 | + r | |
| 511 | + |> Dict.toList | |
| 512 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 513 | + |> String.join "," | |
| 514 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 515 | + | |
| 508 | 516 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 509 | 517 | makeNullableEncoder f m = |
| 510 | 518 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -230,7 +230,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 230 | 230 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 231 | 231 | return invalidValue(l(ref || "object"), val, key, parent); |
| 232 | 232 | } |
| 233 | - const result: any = {}; | |
| 233 | + const result: any = Object.create(null); | |
| 234 | 234 | Object.getOwnPropertyNames(props).forEach(key => { |
| 235 | 235 | const prop = props[key]; |
| 236 | 236 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -241,7 +241,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 241 | 241 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 242 | 242 | } |
| 243 | 243 | }); |
| 244 | - return result; | |
| 244 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -219,7 +219,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 219 | 219 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 220 | 220 | return invalidValue(l(ref || "object"), val, key, parent); |
| 221 | 221 | } |
| 222 | - const result: any = {}; | |
| 222 | + const result: any = Object.create(null); | |
| 223 | 223 | Object.getOwnPropertyNames(props).forEach(key => { |
| 224 | 224 | const prop = props[key]; |
| 225 | 225 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -230,7 +230,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 230 | 230 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 231 | 231 | } |
| 232 | 232 | }); |
| 233 | - return result; | |
| 233 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/88130.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/8a62c.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/908db.json
Melmdefault / QuickType.elm+8 −0
| @@ -85,6 +85,14 @@ encodeStateState x = | ||
| 85 | 85 | |
| 86 | 86 | --- encoder helpers |
| 87 | 87 | |
| 88 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 89 | +makeDictEncoder f m r = | |
| 90 | + r | |
| 91 | + |> Dict.toList | |
| 92 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 93 | + |> String.join "," | |
| 94 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 95 | + | |
| 88 | 96 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 89 | 97 | makeNullableEncoder f m = |
| 90 | 98 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/9617f.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/96f7c.json
Melmdefault / QuickType.elm+8 −0
| @@ -65,6 +65,14 @@ encodeQuickType x = | ||
| 65 | 65 | |
| 66 | 66 | --- encoder helpers |
| 67 | 67 | |
| 68 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 69 | +makeDictEncoder f m r = | |
| 70 | + r | |
| 71 | + |> Dict.toList | |
| 72 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 73 | + |> String.join "," | |
| 74 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 75 | + | |
| 68 | 76 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 69 | 77 | makeNullableEncoder f m = |
| 70 | 78 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/9847b.json
Melmdefault / QuickType.elm+8 −0
| @@ -59,6 +59,14 @@ encodeQuickTypeElement x = | ||
| 59 | 59 | |
| 60 | 60 | --- encoder helpers |
| 61 | 61 | |
| 62 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 63 | +makeDictEncoder f m r = | |
| 64 | + r | |
| 65 | + |> Dict.toList | |
| 66 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 67 | + |> String.join "," | |
| 68 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 69 | + | |
| 62 | 70 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 63 | 71 | makeNullableEncoder f m = |
| 64 | 72 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/9929c.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/996bd.json
Melmdefault / QuickType.elm+8 −0
| @@ -226,6 +226,14 @@ encodeTitle x = case x of | ||
| 226 | 226 | |
| 227 | 227 | --- encoder helpers |
| 228 | 228 | |
| 229 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 230 | +makeDictEncoder f m r = | |
| 231 | + r | |
| 232 | + |> Dict.toList | |
| 233 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 234 | + |> String.join "," | |
| 235 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 236 | + | |
| 229 | 237 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 230 | 238 | makeNullableEncoder f m = |
| 231 | 239 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 152 | 152 | return invalidValue(l(ref || "object"), val, key, parent); |
| 153 | 153 | } |
| 154 | - const result: any = {}; | |
| 154 | + const result: any = Object.create(null); | |
| 155 | 155 | Object.getOwnPropertyNames(props).forEach(key => { |
| 156 | 156 | const prop = props[key]; |
| 157 | 157 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -162,7 +162,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 162 | 162 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 163 | 163 | } |
| 164 | 164 | }); |
| 165 | - return result; | |
| 165 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/9a503.json
Melmdefault / QuickType.elm+8 −0
| @@ -160,6 +160,14 @@ encodeText x = | ||
| 160 | 160 | |
| 161 | 161 | --- encoder helpers |
| 162 | 162 | |
| 163 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 164 | +makeDictEncoder f m r = | |
| 165 | + r | |
| 166 | + |> Dict.toList | |
| 167 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 168 | + |> String.join "," | |
| 169 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 170 | + | |
| 163 | 171 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 164 | 172 | makeNullableEncoder f m = |
| 165 | 173 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -137,7 +137,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 137 | 137 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 138 | 138 | return invalidValue(l(ref || "object"), val, key, parent); |
| 139 | 139 | } |
| 140 | - const result: any = {}; | |
| 140 | + const result: any = Object.create(null); | |
| 141 | 141 | Object.getOwnPropertyNames(props).forEach(key => { |
| 142 | 142 | const prop = props[key]; |
| 143 | 143 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -148,7 +148,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 148 | 148 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 149 | 149 | } |
| 150 | 150 | }); |
| 151 | - return result; | |
| 151 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 135 | 135 | return invalidValue(l(ref || "object"), val, key, parent); |
| 136 | 136 | } |
| 137 | - const result: any = {}; | |
| 137 | + const result: any = Object.create(null); | |
| 138 | 138 | Object.getOwnPropertyNames(props).forEach(key => { |
| 139 | 139 | const prop = props[key]; |
| 140 | 140 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -145,7 +145,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 145 | 145 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 146 | 146 | } |
| 147 | 147 | }); |
| 148 | - return result; | |
| 148 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/9ac3b.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeTitle x = case x of | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 139 | 139 | return invalidValue(l(ref || "object"), val, key, parent); |
| 140 | 140 | } |
| 141 | - const result: any = {}; | |
| 141 | + const result: any = Object.create(null); | |
| 142 | 142 | Object.getOwnPropertyNames(props).forEach(key => { |
| 143 | 143 | const prop = props[key]; |
| 144 | 144 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 150 | 150 | } |
| 151 | 151 | }); |
| 152 | - return result; | |
| 152 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/9eed5.json
Melmdefault / QuickType.elm+8 −0
| @@ -157,6 +157,14 @@ encodeText x = | ||
| 157 | 157 | |
| 158 | 158 | --- encoder helpers |
| 159 | 159 | |
| 160 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 161 | +makeDictEncoder f m r = | |
| 162 | + r | |
| 163 | + |> Dict.toList | |
| 164 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 165 | + |> String.join "," | |
| 166 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 167 | + | |
| 160 | 168 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 161 | 169 | makeNullableEncoder f m = |
| 162 | 170 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 135 | 135 | return invalidValue(l(ref || "object"), val, key, parent); |
| 136 | 136 | } |
| 137 | - const result: any = {}; | |
| 137 | + const result: any = Object.create(null); | |
| 138 | 138 | Object.getOwnPropertyNames(props).forEach(key => { |
| 139 | 139 | const prop = props[key]; |
| 140 | 140 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -145,7 +145,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 145 | 145 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 146 | 146 | } |
| 147 | 147 | }); |
| 148 | - return result; | |
| 148 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/a0496.json
Melmdefault / QuickType.elm+8 −0
| @@ -133,6 +133,14 @@ encodeErrors x = | ||
| 133 | 133 | |
| 134 | 134 | --- encoder helpers |
| 135 | 135 | |
| 136 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 137 | +makeDictEncoder f m r = | |
| 138 | + r | |
| 139 | + |> Dict.toList | |
| 140 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 141 | + |> String.join "," | |
| 142 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 143 | + | |
| 136 | 144 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 137 | 145 | makeNullableEncoder f m = |
| 138 | 146 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 129 | 129 | return invalidValue(l(ref || "object"), val, key, parent); |
| 130 | 130 | } |
| 131 | - const result: any = {}; | |
| 131 | + const result: any = Object.create(null); | |
| 132 | 132 | Object.getOwnPropertyNames(props).forEach(key => { |
| 133 | 133 | const prop = props[key]; |
| 134 | 134 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 140 | 140 | } |
| 141 | 141 | }); |
| 142 | - return result; | |
| 142 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 126 | 126 | return invalidValue(l(ref || "object"), val, key, parent); |
| 127 | 127 | } |
| 128 | - const result: any = {}; | |
| 128 | + const result: any = Object.create(null); | |
| 129 | 129 | Object.getOwnPropertyNames(props).forEach(key => { |
| 130 | 130 | const prop = props[key]; |
| 131 | 131 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 137 | 137 | } |
| 138 | 138 | }); |
| 139 | - return result; | |
| 139 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/a1eca.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/a3d8c.json
Melmdefault / QuickType.elm+8 −0
| @@ -470,6 +470,14 @@ encodeOwner x = | ||
| 470 | 470 | |
| 471 | 471 | --- encoder helpers |
| 472 | 472 | |
| 473 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 474 | +makeDictEncoder f m r = | |
| 475 | + r | |
| 476 | + |> Dict.toList | |
| 477 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 478 | + |> String.join "," | |
| 479 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 480 | + | |
| 473 | 481 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 474 | 482 | makeNullableEncoder f m = |
| 475 | 483 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -223,7 +223,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 223 | 223 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 224 | 224 | return invalidValue(l(ref || "object"), val, key, parent); |
| 225 | 225 | } |
| 226 | - const result: any = {}; | |
| 226 | + const result: any = Object.create(null); | |
| 227 | 227 | Object.getOwnPropertyNames(props).forEach(key => { |
| 228 | 228 | const prop = props[key]; |
| 229 | 229 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -234,7 +234,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 234 | 234 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 235 | 235 | } |
| 236 | 236 | }); |
| 237 | - return result; | |
| 237 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -217,7 +217,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 217 | 217 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 218 | 218 | return invalidValue(l(ref || "object"), val, key, parent); |
| 219 | 219 | } |
| 220 | - const result: any = {}; | |
| 220 | + const result: any = Object.create(null); | |
| 221 | 221 | Object.getOwnPropertyNames(props).forEach(key => { |
| 222 | 222 | const prop = props[key]; |
| 223 | 223 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -228,7 +228,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 228 | 228 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 229 | 229 | } |
| 230 | 230 | }); |
| 231 | - return result; | |
| 231 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/a45b0.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/a71df.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/a9691.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/ab0d1.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/abb4b.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/ac944.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/ad8be.json
Melmdefault / QuickType.elm+8 −0
| @@ -307,6 +307,14 @@ encodeTitle x = case x of | ||
| 307 | 307 | |
| 308 | 308 | --- encoder helpers |
| 309 | 309 | |
| 310 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 311 | +makeDictEncoder f m r = | |
| 312 | + r | |
| 313 | + |> Dict.toList | |
| 314 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 315 | + |> String.join "," | |
| 316 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 317 | + | |
| 310 | 318 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 311 | 319 | makeNullableEncoder f m = |
| 312 | 320 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -174,7 +174,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 174 | 174 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 175 | 175 | return invalidValue(l(ref || "object"), val, key, parent); |
| 176 | 176 | } |
| 177 | - const result: any = {}; | |
| 177 | + const result: any = Object.create(null); | |
| 178 | 178 | Object.getOwnPropertyNames(props).forEach(key => { |
| 179 | 179 | const prop = props[key]; |
| 180 | 180 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -185,7 +185,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 185 | 185 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 186 | 186 | } |
| 187 | 187 | }); |
| 188 | - return result; | |
| 188 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/ae7f0.json
Melmdefault / QuickType.elm+8 −0
| @@ -407,6 +407,14 @@ encodeKind x = case x of | ||
| 407 | 407 | |
| 408 | 408 | --- encoder helpers |
| 409 | 409 | |
| 410 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 411 | +makeDictEncoder f m r = | |
| 412 | + r | |
| 413 | + |> Dict.toList | |
| 414 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 415 | + |> String.join "," | |
| 416 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 417 | + | |
| 410 | 418 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 411 | 419 | makeNullableEncoder f m = |
| 412 | 420 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -204,7 +204,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 204 | 204 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 205 | 205 | return invalidValue(l(ref || "object"), val, key, parent); |
| 206 | 206 | } |
| 207 | - const result: any = {}; | |
| 207 | + const result: any = Object.create(null); | |
| 208 | 208 | Object.getOwnPropertyNames(props).forEach(key => { |
| 209 | 209 | const prop = props[key]; |
| 210 | 210 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -215,7 +215,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 215 | 215 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 216 | 216 | } |
| 217 | 217 | }); |
| 218 | - return result; | |
| 218 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -195,7 +195,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 195 | 195 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 196 | 196 | return invalidValue(l(ref || "object"), val, key, parent); |
| 197 | 197 | } |
| 198 | - const result: any = {}; | |
| 198 | + const result: any = Object.create(null); | |
| 199 | 199 | Object.getOwnPropertyNames(props).forEach(key => { |
| 200 | 200 | const prop = props[key]; |
| 201 | 201 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -206,7 +206,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 206 | 206 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 207 | 207 | } |
| 208 | 208 | }); |
| 209 | - return result; | |
| 209 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/ae9ca.json
Melmdefault / QuickType.elm+8 −0
| @@ -240,6 +240,14 @@ encodeWard x = case x of | ||
| 240 | 240 | |
| 241 | 241 | --- encoder helpers |
| 242 | 242 | |
| 243 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 244 | +makeDictEncoder f m r = | |
| 245 | + r | |
| 246 | + |> Dict.toList | |
| 247 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 248 | + |> String.join "," | |
| 249 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 250 | + | |
| 243 | 251 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 244 | 252 | makeNullableEncoder f m = |
| 245 | 253 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -153,7 +153,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 153 | 153 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 154 | 154 | return invalidValue(l(ref || "object"), val, key, parent); |
| 155 | 155 | } |
| 156 | - const result: any = {}; | |
| 156 | + const result: any = Object.create(null); | |
| 157 | 157 | Object.getOwnPropertyNames(props).forEach(key => { |
| 158 | 158 | const prop = props[key]; |
| 159 | 159 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -164,7 +164,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 164 | 164 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 165 | 165 | } |
| 166 | 166 | }); |
| 167 | - return result; | |
| 167 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -143,7 +143,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 143 | 143 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 144 | 144 | return invalidValue(l(ref || "object"), val, key, parent); |
| 145 | 145 | } |
| 146 | - const result: any = {}; | |
| 146 | + const result: any = Object.create(null); | |
| 147 | 147 | Object.getOwnPropertyNames(props).forEach(key => { |
| 148 | 148 | const prop = props[key]; |
| 149 | 149 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -154,7 +154,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 154 | 154 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 155 | 155 | } |
| 156 | 156 | }); |
| 157 | - return result; | |
| 157 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/af2d1.json
Melmdefault / QuickType.elm+8 −0
| @@ -474,6 +474,14 @@ encodeStatus x = case x of | ||
| 474 | 474 | |
| 475 | 475 | --- encoder helpers |
| 476 | 476 | |
| 477 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 478 | +makeDictEncoder f m r = | |
| 479 | + r | |
| 480 | + |> Dict.toList | |
| 481 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 482 | + |> String.join "," | |
| 483 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 484 | + | |
| 477 | 485 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 478 | 486 | makeNullableEncoder f m = |
| 479 | 487 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -215,7 +215,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 215 | 215 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 216 | 216 | return invalidValue(l(ref || "object"), val, key, parent); |
| 217 | 217 | } |
| 218 | - const result: any = {}; | |
| 218 | + const result: any = Object.create(null); | |
| 219 | 219 | Object.getOwnPropertyNames(props).forEach(key => { |
| 220 | 220 | const prop = props[key]; |
| 221 | 221 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 227 | 227 | } |
| 228 | 228 | }); |
| 229 | - return result; | |
| 229 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -193,7 +193,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 193 | 193 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 194 | 194 | return invalidValue(l(ref || "object"), val, key, parent); |
| 195 | 195 | } |
| 196 | - const result: any = {}; | |
| 196 | + const result: any = Object.create(null); | |
| 197 | 197 | Object.getOwnPropertyNames(props).forEach(key => { |
| 198 | 198 | const prop = props[key]; |
| 199 | 199 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -204,7 +204,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 204 | 204 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 205 | 205 | } |
| 206 | 206 | }); |
| 207 | - return result; | |
| 207 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/b4865.json
Melmdefault / QuickType.elm+8 −0
| @@ -162,6 +162,14 @@ encodeNametype x = case x of | ||
| 162 | 162 | |
| 163 | 163 | --- encoder helpers |
| 164 | 164 | |
| 165 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 166 | +makeDictEncoder f m r = | |
| 167 | + r | |
| 168 | + |> Dict.toList | |
| 169 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 170 | + |> String.join "," | |
| 171 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 172 | + | |
| 165 | 173 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 166 | 174 | makeNullableEncoder f m = |
| 167 | 175 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/b6f2c.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/b6fe5.json
Melmdefault / QuickType.elm+8 −0
| @@ -59,6 +59,14 @@ encodeQuickType x = | ||
| 59 | 59 | |
| 60 | 60 | --- encoder helpers |
| 61 | 61 | |
| 62 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 63 | +makeDictEncoder f m r = | |
| 64 | + r | |
| 65 | + |> Dict.toList | |
| 66 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 67 | + |> String.join "," | |
| 68 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 69 | + | |
| 62 | 70 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 63 | 71 | makeNullableEncoder f m = |
| 64 | 72 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/b9f64.json
Melmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/bb1ec.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/be234.json
Melmdefault / QuickType.elm+8 −0
| @@ -636,6 +636,14 @@ encodeKind x = case x of | ||
| 636 | 636 | |
| 637 | 637 | --- encoder helpers |
| 638 | 638 | |
| 639 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 640 | +makeDictEncoder f m r = | |
| 641 | + r | |
| 642 | + |> Dict.toList | |
| 643 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 644 | + |> String.join "," | |
| 645 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 646 | + | |
| 639 | 647 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 640 | 648 | makeNullableEncoder f m = |
| 641 | 649 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -269,7 +269,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 269 | 269 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 270 | 270 | return invalidValue(l(ref || "object"), val, key, parent); |
| 271 | 271 | } |
| 272 | - const result: any = {}; | |
| 272 | + const result: any = Object.create(null); | |
| 273 | 273 | Object.getOwnPropertyNames(props).forEach(key => { |
| 274 | 274 | const prop = props[key]; |
| 275 | 275 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -280,7 +280,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 280 | 280 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 281 | 281 | } |
| 282 | 282 | }); |
| 283 | - return result; | |
| 283 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -256,7 +256,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 256 | 256 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 257 | 257 | return invalidValue(l(ref || "object"), val, key, parent); |
| 258 | 258 | } |
| 259 | - const result: any = {}; | |
| 259 | + const result: any = Object.create(null); | |
| 260 | 260 | Object.getOwnPropertyNames(props).forEach(key => { |
| 261 | 261 | const prop = props[key]; |
| 262 | 262 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -267,7 +267,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 267 | 267 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 268 | 268 | } |
| 269 | 269 | }); |
| 270 | - return result; | |
| 270 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/c0356.json
Melmdefault / QuickType.elm+9 −1
| @@ -60,7 +60,7 @@ quickType = | ||
| 60 | 60 | encodeQuickType : QuickType -> Jenc.Value |
| 61 | 61 | encodeQuickType x = |
| 62 | 62 | Jenc.object |
| 63 | - [ ("data", Jenc.dict identity encodeDatum x.data) | |
| 63 | + [ ("data", makeDictEncoder identity encodeDatum x.data) | |
| 64 | 64 | , ("description", encodeDescription x.description) |
| 65 | 65 | ] |
| 66 | 66 | |
| @@ -94,6 +94,14 @@ encodeDescription x = | ||
| 94 | 94 | |
| 95 | 95 | --- encoder helpers |
| 96 | 96 | |
| 97 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 98 | +makeDictEncoder f m r = | |
| 99 | + r | |
| 100 | + |> Dict.toList | |
| 101 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 102 | + |> String.join "," | |
| 103 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 104 | + | |
| 97 | 105 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 98 | 106 | makeNullableEncoder f m = |
| 99 | 107 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/c0a3a.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/c3303.json
Melmdefault / QuickType.elm+8 −0
| @@ -449,6 +449,14 @@ encodePagination x = | ||
| 449 | 449 | |
| 450 | 450 | --- encoder helpers |
| 451 | 451 | |
| 452 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 453 | +makeDictEncoder f m r = | |
| 454 | + r | |
| 455 | + |> Dict.toList | |
| 456 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 457 | + |> String.join "," | |
| 458 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 459 | + | |
| 452 | 460 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 453 | 461 | makeNullableEncoder f m = |
| 454 | 462 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -220,7 +220,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 220 | 220 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 221 | 221 | return invalidValue(l(ref || "object"), val, key, parent); |
| 222 | 222 | } |
| 223 | - const result: any = {}; | |
| 223 | + const result: any = Object.create(null); | |
| 224 | 224 | Object.getOwnPropertyNames(props).forEach(key => { |
| 225 | 225 | const prop = props[key]; |
| 226 | 226 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -231,7 +231,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 231 | 231 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 232 | 232 | } |
| 233 | 233 | }); |
| 234 | - return result; | |
| 234 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -214,7 +214,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 214 | 214 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 215 | 215 | return invalidValue(l(ref || "object"), val, key, parent); |
| 216 | 216 | } |
| 217 | - const result: any = {}; | |
| 217 | + const result: any = Object.create(null); | |
| 218 | 218 | Object.getOwnPropertyNames(props).forEach(key => { |
| 219 | 219 | const prop = props[key]; |
| 220 | 220 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -225,7 +225,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 225 | 225 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 226 | 226 | } |
| 227 | 227 | }); |
| 228 | - return result; | |
| 228 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/c6cfd.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeCountry x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/c8c7e.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeFluffyQuickType x = | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/cb0cc.json
Melmdefault / QuickType.elm+8 −0
| @@ -135,6 +135,14 @@ encodeLaureate x = | ||
| 135 | 135 | |
| 136 | 136 | --- encoder helpers |
| 137 | 137 | |
| 138 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 139 | +makeDictEncoder f m r = | |
| 140 | + r | |
| 141 | + |> Dict.toList | |
| 142 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 143 | + |> String.join "," | |
| 144 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 145 | + | |
| 138 | 146 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 139 | 147 | makeNullableEncoder f m = |
| 140 | 148 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 131 | 131 | return invalidValue(l(ref || "object"), val, key, parent); |
| 132 | 132 | } |
| 133 | - const result: any = {}; | |
| 133 | + const result: any = Object.create(null); | |
| 134 | 134 | Object.getOwnPropertyNames(props).forEach(key => { |
| 135 | 135 | const prop = props[key]; |
| 136 | 136 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -141,7 +141,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 141 | 141 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 142 | 142 | } |
| 143 | 143 | }); |
| 144 | - return result; | |
| 144 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 125 | 125 | return invalidValue(l(ref || "object"), val, key, parent); |
| 126 | 126 | } |
| 127 | - const result: any = {}; | |
| 127 | + const result: any = Object.create(null); | |
| 128 | 128 | Object.getOwnPropertyNames(props).forEach(key => { |
| 129 | 129 | const prop = props[key]; |
| 130 | 130 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 136 | 136 | } |
| 137 | 137 | }); |
| 138 | - return result; | |
| 138 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/cb81e.json
Melmdefault / QuickType.elm+9 −1
| @@ -55,7 +55,7 @@ quickType = | ||
| 55 | 55 | encodeQuickType : QuickType -> Jenc.Value |
| 56 | 56 | encodeQuickType x = |
| 57 | 57 | Jenc.object |
| 58 | - [ ("data", Jenc.dict identity Jenc.string x.data) | |
| 58 | + [ ("data", makeDictEncoder identity Jenc.string x.data) | |
| 59 | 59 | , ("description", encodeDescription x.description) |
| 60 | 60 | ] |
| 61 | 61 | |
| @@ -78,6 +78,14 @@ encodeDescription x = | ||
| 78 | 78 | |
| 79 | 79 | --- encoder helpers |
| 80 | 80 | |
| 81 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 82 | +makeDictEncoder f m r = | |
| 83 | + r | |
| 84 | + |> Dict.toList | |
| 85 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 86 | + |> String.join "," | |
| 87 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 88 | + | |
| 81 | 89 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 82 | 90 | makeNullableEncoder f m = |
| 83 | 91 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/ccd18.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/cd238.json
Melmdefault / QuickType.elm+8 −0
| @@ -161,6 +161,14 @@ encodeMeta x = | ||
| 161 | 161 | |
| 162 | 162 | --- encoder helpers |
| 163 | 163 | |
| 164 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 165 | +makeDictEncoder f m r = | |
| 166 | + r | |
| 167 | + |> Dict.toList | |
| 168 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 169 | + |> String.join "," | |
| 170 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 171 | + | |
| 164 | 172 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 165 | 173 | makeNullableEncoder f m = |
| 166 | 174 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 141 | 141 | return invalidValue(l(ref || "object"), val, key, parent); |
| 142 | 142 | } |
| 143 | - const result: any = {}; | |
| 143 | + const result: any = Object.create(null); | |
| 144 | 144 | Object.getOwnPropertyNames(props).forEach(key => { |
| 145 | 145 | const prop = props[key]; |
| 146 | 146 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -151,7 +151,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 151 | 151 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | - return result; | |
| 154 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/cd463.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/cda6c.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeFluffyQuickType x = | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/cf0d8.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/cfbce.json
Melmdefault / QuickType.elm+9 −1
| @@ -51,11 +51,19 @@ encodeQuickType x = | ||
| 51 | 51 | Jenc.object |
| 52 | 52 | [ ("base", Jenc.string x.base) |
| 53 | 53 | , ("date", Jenc.string x.date) |
| 54 | - , ("rates", Jenc.dict identity Jenc.float x.rates) | |
| 54 | + , ("rates", makeDictEncoder identity Jenc.float x.rates) | |
| 55 | 55 | ] |
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/d0908.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeTotalPopulation x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/d23d5.json
Melmdefault / QuickType.elm+8 −0
| @@ -114,6 +114,14 @@ encodeResult x = | ||
| 114 | 114 | |
| 115 | 115 | --- encoder helpers |
| 116 | 116 | |
| 117 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 118 | +makeDictEncoder f m r = | |
| 119 | + r | |
| 120 | + |> Dict.toList | |
| 121 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 122 | + |> String.join "," | |
| 123 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 124 | + | |
| 117 | 125 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 118 | 126 | makeNullableEncoder f m = |
| 119 | 127 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 126 | 126 | return invalidValue(l(ref || "object"), val, key, parent); |
| 127 | 127 | } |
| 128 | - const result: any = {}; | |
| 128 | + const result: any = Object.create(null); | |
| 129 | 129 | Object.getOwnPropertyNames(props).forEach(key => { |
| 130 | 130 | const prop = props[key]; |
| 131 | 131 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 137 | 137 | } |
| 138 | 138 | }); |
| 139 | - return result; | |
| 139 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 123 | 123 | return invalidValue(l(ref || "object"), val, key, parent); |
| 124 | 124 | } |
| 125 | - const result: any = {}; | |
| 125 | + const result: any = Object.create(null); | |
| 126 | 126 | Object.getOwnPropertyNames(props).forEach(key => { |
| 127 | 127 | const prop = props[key]; |
| 128 | 128 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 134 | 134 | } |
| 135 | 135 | }); |
| 136 | - return result; | |
| 136 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/dbfb3.json
Melmdefault / QuickType.elm+8 −0
| @@ -416,6 +416,14 @@ encodeWind x = | ||
| 416 | 416 | |
| 417 | 417 | --- encoder helpers |
| 418 | 418 | |
| 419 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 420 | +makeDictEncoder f m r = | |
| 421 | + r | |
| 422 | + |> Dict.toList | |
| 423 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 424 | + |> String.join "," | |
| 425 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 426 | + | |
| 419 | 427 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 420 | 428 | makeNullableEncoder f m = |
| 421 | 429 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -209,7 +209,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 209 | 209 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 210 | 210 | return invalidValue(l(ref || "object"), val, key, parent); |
| 211 | 211 | } |
| 212 | - const result: any = {}; | |
| 212 | + const result: any = Object.create(null); | |
| 213 | 213 | Object.getOwnPropertyNames(props).forEach(key => { |
| 214 | 214 | const prop = props[key]; |
| 215 | 215 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -220,7 +220,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 220 | 220 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 221 | 221 | } |
| 222 | 222 | }); |
| 223 | - return result; | |
| 223 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -207,7 +207,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 207 | 207 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 208 | 208 | return invalidValue(l(ref || "object"), val, key, parent); |
| 209 | 209 | } |
| 210 | - const result: any = {}; | |
| 210 | + const result: any = Object.create(null); | |
| 211 | 211 | Object.getOwnPropertyNames(props).forEach(key => { |
| 212 | 212 | const prop = props[key]; |
| 213 | 213 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -218,7 +218,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 218 | 218 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 219 | 219 | } |
| 220 | 220 | }); |
| 221 | - return result; | |
| 221 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/dc44f.json
Melmdefault / QuickType.elm+8 −0
| @@ -512,6 +512,14 @@ encodeType x = case x of | ||
| 512 | 512 | |
| 513 | 513 | --- encoder helpers |
| 514 | 514 | |
| 515 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 516 | +makeDictEncoder f m r = | |
| 517 | + r | |
| 518 | + |> Dict.toList | |
| 519 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 520 | + |> String.join "," | |
| 521 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 522 | + | |
| 515 | 523 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 516 | 524 | makeNullableEncoder f m = |
| 517 | 525 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -233,7 +233,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 233 | 233 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 234 | 234 | return invalidValue(l(ref || "object"), val, key, parent); |
| 235 | 235 | } |
| 236 | - const result: any = {}; | |
| 236 | + const result: any = Object.create(null); | |
| 237 | 237 | Object.getOwnPropertyNames(props).forEach(key => { |
| 238 | 238 | const prop = props[key]; |
| 239 | 239 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -244,7 +244,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 244 | 244 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 245 | 245 | } |
| 246 | 246 | }); |
| 247 | - return result; | |
| 247 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -175,7 +175,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 175 | 175 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 176 | 176 | return invalidValue(l(ref || "object"), val, key, parent); |
| 177 | 177 | } |
| 178 | - const result: any = {}; | |
| 178 | + const result: any = Object.create(null); | |
| 179 | 179 | Object.getOwnPropertyNames(props).forEach(key => { |
| 180 | 180 | const prop = props[key]; |
| 181 | 181 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -186,7 +186,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 186 | 186 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 187 | 187 | } |
| 188 | 188 | }); |
| 189 | - return result; | |
| 189 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/dd1ce.json
Melmdefault / QuickType.elm+8 −0
| @@ -512,6 +512,14 @@ encodeType x = case x of | ||
| 512 | 512 | |
| 513 | 513 | --- encoder helpers |
| 514 | 514 | |
| 515 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 516 | +makeDictEncoder f m r = | |
| 517 | + r | |
| 518 | + |> Dict.toList | |
| 519 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 520 | + |> String.join "," | |
| 521 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 522 | + | |
| 515 | 523 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 516 | 524 | makeNullableEncoder f m = |
| 517 | 525 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -233,7 +233,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 233 | 233 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 234 | 234 | return invalidValue(l(ref || "object"), val, key, parent); |
| 235 | 235 | } |
| 236 | - const result: any = {}; | |
| 236 | + const result: any = Object.create(null); | |
| 237 | 237 | Object.getOwnPropertyNames(props).forEach(key => { |
| 238 | 238 | const prop = props[key]; |
| 239 | 239 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -244,7 +244,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 244 | 244 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 245 | 245 | } |
| 246 | 246 | }); |
| 247 | - return result; | |
| 247 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -175,7 +175,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 175 | 175 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 176 | 176 | return invalidValue(l(ref || "object"), val, key, parent); |
| 177 | 177 | } |
| 178 | - const result: any = {}; | |
| 178 | + const result: any = Object.create(null); | |
| 179 | 179 | Object.getOwnPropertyNames(props).forEach(key => { |
| 180 | 180 | const prop = props[key]; |
| 181 | 181 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -186,7 +186,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 186 | 186 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 187 | 187 | } |
| 188 | 188 | }); |
| 189 | - return result; | |
| 189 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/dec3a.json
Melmdefault / QuickType.elm+8 −0
| @@ -257,6 +257,14 @@ encodeLocation x = | ||
| 257 | 257 | |
| 258 | 258 | --- encoder helpers |
| 259 | 259 | |
| 260 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 261 | +makeDictEncoder f m r = | |
| 262 | + r | |
| 263 | + |> Dict.toList | |
| 264 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 265 | + |> String.join "," | |
| 266 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 267 | + | |
| 260 | 268 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 261 | 269 | makeNullableEncoder f m = |
| 262 | 270 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -168,7 +168,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 168 | 168 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 169 | 169 | return invalidValue(l(ref || "object"), val, key, parent); |
| 170 | 170 | } |
| 171 | - const result: any = {}; | |
| 171 | + const result: any = Object.create(null); | |
| 172 | 172 | Object.getOwnPropertyNames(props).forEach(key => { |
| 173 | 173 | const prop = props[key]; |
| 174 | 174 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -179,7 +179,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 179 | 179 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 180 | 180 | } |
| 181 | 181 | }); |
| 182 | - return result; | |
| 182 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -168,7 +168,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 168 | 168 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 169 | 169 | return invalidValue(l(ref || "object"), val, key, parent); |
| 170 | 170 | } |
| 171 | - const result: any = {}; | |
| 171 | + const result: any = Object.create(null); | |
| 172 | 172 | Object.getOwnPropertyNames(props).forEach(key => { |
| 173 | 173 | const prop = props[key]; |
| 174 | 174 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -179,7 +179,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 179 | 179 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 180 | 180 | } |
| 181 | 181 | }); |
| 182 | - return result; | |
| 182 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/df957.json
Melmdefault / QuickType.elm+8 −0
| @@ -396,6 +396,14 @@ encodeWind x = | ||
| 396 | 396 | |
| 397 | 397 | --- encoder helpers |
| 398 | 398 | |
| 399 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 400 | +makeDictEncoder f m r = | |
| 401 | + r | |
| 402 | + |> Dict.toList | |
| 403 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 404 | + |> String.join "," | |
| 405 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 406 | + | |
| 399 | 407 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 400 | 408 | makeNullableEncoder f m = |
| 401 | 409 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -205,7 +205,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 205 | 205 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 206 | 206 | return invalidValue(l(ref || "object"), val, key, parent); |
| 207 | 207 | } |
| 208 | - const result: any = {}; | |
| 208 | + const result: any = Object.create(null); | |
| 209 | 209 | Object.getOwnPropertyNames(props).forEach(key => { |
| 210 | 210 | const prop = props[key]; |
| 211 | 211 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -216,7 +216,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 216 | 216 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 217 | 217 | } |
| 218 | 218 | }); |
| 219 | - return result; | |
| 219 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e0ac7.json
Melmdefault / QuickType.elm+8 −0
| @@ -432,6 +432,14 @@ encodePagination x = | ||
| 432 | 432 | |
| 433 | 433 | --- encoder helpers |
| 434 | 434 | |
| 435 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 436 | +makeDictEncoder f m r = | |
| 437 | + r | |
| 438 | + |> Dict.toList | |
| 439 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 440 | + |> String.join "," | |
| 441 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 442 | + | |
| 435 | 443 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 436 | 444 | makeNullableEncoder f m = |
| 437 | 445 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -217,7 +217,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 217 | 217 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 218 | 218 | return invalidValue(l(ref || "object"), val, key, parent); |
| 219 | 219 | } |
| 220 | - const result: any = {}; | |
| 220 | + const result: any = Object.create(null); | |
| 221 | 221 | Object.getOwnPropertyNames(props).forEach(key => { |
| 222 | 222 | const prop = props[key]; |
| 223 | 223 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -228,7 +228,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 228 | 228 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 229 | 229 | } |
| 230 | 230 | }); |
| 231 | - return result; | |
| 231 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -213,7 +213,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 213 | 213 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 214 | 214 | return invalidValue(l(ref || "object"), val, key, parent); |
| 215 | 215 | } |
| 216 | - const result: any = {}; | |
| 216 | + const result: any = Object.create(null); | |
| 217 | 217 | Object.getOwnPropertyNames(props).forEach(key => { |
| 218 | 218 | const prop = props[key]; |
| 219 | 219 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -224,7 +224,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 224 | 224 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 225 | 225 | } |
| 226 | 226 | }); |
| 227 | - return result; | |
| 227 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e2915.json
Melmdefault / QuickType.elm+8 −0
| @@ -413,6 +413,14 @@ encodeWind x = | ||
| 413 | 413 | |
| 414 | 414 | --- encoder helpers |
| 415 | 415 | |
| 416 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 417 | +makeDictEncoder f m r = | |
| 418 | + r | |
| 419 | + |> Dict.toList | |
| 420 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 421 | + |> String.join "," | |
| 422 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 423 | + | |
| 416 | 424 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 417 | 425 | makeNullableEncoder f m = |
| 418 | 426 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -208,7 +208,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 208 | 208 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 209 | 209 | return invalidValue(l(ref || "object"), val, key, parent); |
| 210 | 210 | } |
| 211 | - const result: any = {}; | |
| 211 | + const result: any = Object.create(null); | |
| 212 | 212 | Object.getOwnPropertyNames(props).forEach(key => { |
| 213 | 213 | const prop = props[key]; |
| 214 | 214 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -219,7 +219,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 219 | 219 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 220 | 220 | } |
| 221 | 221 | }); |
| 222 | - return result; | |
| 222 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -207,7 +207,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 207 | 207 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 208 | 208 | return invalidValue(l(ref || "object"), val, key, parent); |
| 209 | 209 | } |
| 210 | - const result: any = {}; | |
| 210 | + const result: any = Object.create(null); | |
| 211 | 211 | Object.getOwnPropertyNames(props).forEach(key => { |
| 212 | 212 | const prop = props[key]; |
| 213 | 213 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -218,7 +218,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 218 | 218 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 219 | 219 | } |
| 220 | 220 | }); |
| 221 | - return result; | |
| 221 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e2a58.json
Melmdefault / QuickType.elm+8 −0
| @@ -59,6 +59,14 @@ encodeQuickTypeElement x = | ||
| 59 | 59 | |
| 60 | 60 | --- encoder helpers |
| 61 | 61 | |
| 62 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 63 | +makeDictEncoder f m r = | |
| 64 | + r | |
| 65 | + |> Dict.toList | |
| 66 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 67 | + |> String.join "," | |
| 68 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 69 | + | |
| 62 | 70 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 63 | 71 | makeNullableEncoder f m = |
| 64 | 72 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/e324e.json
Melmdefault / QuickType.elm+9 −1
| @@ -166,7 +166,7 @@ rate = | ||
| 166 | 166 | encodeRate : Rate -> Jenc.Value |
| 167 | 167 | encodeRate x = |
| 168 | 168 | Jenc.object |
| 169 | - [ ("properties", Jenc.dict identity encodeProperty x.properties) | |
| 169 | + [ ("properties", makeDictEncoder identity encodeProperty x.properties) | |
| 170 | 170 | ] |
| 171 | 171 | |
| 172 | 172 | property : Jdec.Decoder Property |
| @@ -322,6 +322,14 @@ encodeItems x = | ||
| 322 | 322 | |
| 323 | 323 | --- encoder helpers |
| 324 | 324 | |
| 325 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 326 | +makeDictEncoder f m r = | |
| 327 | + r | |
| 328 | + |> Dict.toList | |
| 329 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 330 | + |> String.join "," | |
| 331 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 332 | + | |
| 325 | 333 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 326 | 334 | makeNullableEncoder f m = |
| 327 | 335 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -179,7 +179,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 179 | 179 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 180 | 180 | return invalidValue(l(ref || "object"), val, key, parent); |
| 181 | 181 | } |
| 182 | - const result: any = {}; | |
| 182 | + const result: any = Object.create(null); | |
| 183 | 183 | Object.getOwnPropertyNames(props).forEach(key => { |
| 184 | 184 | const prop = props[key]; |
| 185 | 185 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -190,7 +190,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 190 | 190 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 191 | 191 | } |
| 192 | 192 | }); |
| 193 | - return result; | |
| 193 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -178,7 +178,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 178 | 178 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 179 | 179 | return invalidValue(l(ref || "object"), val, key, parent); |
| 180 | 180 | } |
| 181 | - const result: any = {}; | |
| 181 | + const result: any = Object.create(null); | |
| 182 | 182 | Object.getOwnPropertyNames(props).forEach(key => { |
| 183 | 183 | const prop = props[key]; |
| 184 | 184 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -189,7 +189,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 189 | 189 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 190 | 190 | } |
| 191 | 191 | }); |
| 192 | - return result; | |
| 192 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e53b5.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeFluffyQuickType x = | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 132 | 132 | return invalidValue(l(ref || "object"), val, key, parent); |
| 133 | 133 | } |
| 134 | - const result: any = {}; | |
| 134 | + const result: any = Object.create(null); | |
| 135 | 135 | Object.getOwnPropertyNames(props).forEach(key => { |
| 136 | 136 | const prop = props[key]; |
| 137 | 137 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -142,7 +142,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 142 | 142 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 143 | 143 | } |
| 144 | 144 | }); |
| 145 | - return result; | |
| 145 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e64a0.json
Melmdefault / QuickType.elm+8 −0
| @@ -99,6 +99,14 @@ encodeHeaders x = | ||
| 99 | 99 | |
| 100 | 100 | --- encoder helpers |
| 101 | 101 | |
| 102 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 103 | +makeDictEncoder f m r = | |
| 104 | + r | |
| 105 | + |> Dict.toList | |
| 106 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 107 | + |> String.join "," | |
| 108 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 109 | + | |
| 102 | 110 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 103 | 111 | makeNullableEncoder f m = |
| 104 | 112 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e8a0b.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/e8b04.json
Melmdefault / QuickType.elm+8 −0
| @@ -1112,6 +1112,14 @@ encodeViewType x = case x of | ||
| 1112 | 1112 | |
| 1113 | 1113 | --- encoder helpers |
| 1114 | 1114 | |
| 1115 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1116 | +makeDictEncoder f m r = | |
| 1117 | + r | |
| 1118 | + |> Dict.toList | |
| 1119 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1120 | + |> String.join "," | |
| 1121 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1122 | + | |
| 1115 | 1123 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1116 | 1124 | makeNullableEncoder f m = |
| 1117 | 1125 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -377,7 +377,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 377 | 377 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 378 | 378 | return invalidValue(l(ref || "object"), val, key, parent); |
| 379 | 379 | } |
| 380 | - const result: any = {}; | |
| 380 | + const result: any = Object.create(null); | |
| 381 | 381 | Object.getOwnPropertyNames(props).forEach(key => { |
| 382 | 382 | const prop = props[key]; |
| 383 | 383 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -388,7 +388,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 388 | 388 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 389 | 389 | } |
| 390 | 390 | }); |
| 391 | - return result; | |
| 391 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -338,7 +338,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 338 | 338 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 339 | 339 | return invalidValue(l(ref || "object"), val, key, parent); |
| 340 | 340 | } |
| 341 | - const result: any = {}; | |
| 341 | + const result: any = Object.create(null); | |
| 342 | 342 | Object.getOwnPropertyNames(props).forEach(key => { |
| 343 | 343 | const prop = props[key]; |
| 344 | 344 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -349,7 +349,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 349 | 349 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 350 | 350 | } |
| 351 | 351 | }); |
| 352 | - return result; | |
| 352 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/ed095.json
Melmdefault / QuickType.elm+9 −1
| @@ -36,10 +36,18 @@ quickType : Jdec.Decoder QuickType | ||
| 36 | 36 | quickType = Jdec.dict Jdec.string |
| 37 | 37 | |
| 38 | 38 | quickTypeToString : QuickType -> String |
| 39 | -quickTypeToString r = Jenc.encode 0 (Jenc.dict identity Jenc.string r) | |
| 39 | +quickTypeToString r = Jenc.encode 0 (makeDictEncoder identity Jenc.string r) | |
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f22f5.json
Melmdefault / QuickType.elm+8 −0
| @@ -390,6 +390,14 @@ encodeKind x = case x of | ||
| 390 | 390 | |
| 391 | 391 | --- encoder helpers |
| 392 | 392 | |
| 393 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 394 | +makeDictEncoder f m r = | |
| 395 | + r | |
| 396 | + |> Dict.toList | |
| 397 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 398 | + |> String.join "," | |
| 399 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 400 | + | |
| 393 | 401 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 394 | 402 | makeNullableEncoder f m = |
| 395 | 403 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -201,7 +201,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 201 | 201 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 202 | 202 | return invalidValue(l(ref || "object"), val, key, parent); |
| 203 | 203 | } |
| 204 | - const result: any = {}; | |
| 204 | + const result: any = Object.create(null); | |
| 205 | 205 | Object.getOwnPropertyNames(props).forEach(key => { |
| 206 | 206 | const prop = props[key]; |
| 207 | 207 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -212,7 +212,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 212 | 212 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 213 | 213 | } |
| 214 | 214 | }); |
| 215 | - return result; | |
| 215 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -193,7 +193,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 193 | 193 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 194 | 194 | return invalidValue(l(ref || "object"), val, key, parent); |
| 195 | 195 | } |
| 196 | - const result: any = {}; | |
| 196 | + const result: any = Object.create(null); | |
| 197 | 197 | Object.getOwnPropertyNames(props).forEach(key => { |
| 198 | 198 | const prop = props[key]; |
| 199 | 199 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -204,7 +204,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 204 | 204 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 205 | 205 | } |
| 206 | 206 | }); |
| 207 | - return result; | |
| 207 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f3139.json
Melmdefault / QuickType.elm+8 −0
| @@ -59,6 +59,14 @@ encodeQuickTypeElement x = | ||
| 59 | 59 | |
| 60 | 60 | --- encoder helpers |
| 61 | 61 | |
| 62 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 63 | +makeDictEncoder f m r = | |
| 64 | + r | |
| 65 | + |> Dict.toList | |
| 66 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 67 | + |> String.join "," | |
| 68 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 69 | + | |
| 62 | 70 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 63 | 71 | makeNullableEncoder f m = |
| 64 | 72 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f3edf.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f466a.json
Melmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeCountry x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f6a65.json
Melmdefault / QuickType.elm+8 −0
| @@ -461,6 +461,14 @@ encodePagination x = | ||
| 461 | 461 | |
| 462 | 462 | --- encoder helpers |
| 463 | 463 | |
| 464 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 465 | +makeDictEncoder f m r = | |
| 466 | + r | |
| 467 | + |> Dict.toList | |
| 468 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 469 | + |> String.join "," | |
| 470 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 471 | + | |
| 464 | 472 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 465 | 473 | makeNullableEncoder f m = |
| 466 | 474 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -224,7 +224,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 224 | 224 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 225 | 225 | return invalidValue(l(ref || "object"), val, key, parent); |
| 226 | 226 | } |
| 227 | - const result: any = {}; | |
| 227 | + const result: any = Object.create(null); | |
| 228 | 228 | Object.getOwnPropertyNames(props).forEach(key => { |
| 229 | 229 | const prop = props[key]; |
| 230 | 230 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -235,7 +235,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 235 | 235 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 236 | 236 | } |
| 237 | 237 | }); |
| 238 | - return result; | |
| 238 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -215,7 +215,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 215 | 215 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 216 | 216 | return invalidValue(l(ref || "object"), val, key, parent); |
| 217 | 217 | } |
| 218 | - const result: any = {}; | |
| 218 | + const result: any = Object.create(null); | |
| 219 | 219 | Object.getOwnPropertyNames(props).forEach(key => { |
| 220 | 220 | const prop = props[key]; |
| 221 | 221 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 227 | 227 | } |
| 228 | 228 | }); |
| 229 | - return result; | |
| 229 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f74d5.json
Melmdefault / QuickType.elm+8 −0
| @@ -467,6 +467,14 @@ encodeOwner x = | ||
| 467 | 467 | |
| 468 | 468 | --- encoder helpers |
| 469 | 469 | |
| 470 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 471 | +makeDictEncoder f m r = | |
| 472 | + r | |
| 473 | + |> Dict.toList | |
| 474 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 475 | + |> String.join "," | |
| 476 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 477 | + | |
| 470 | 478 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 471 | 479 | makeNullableEncoder f m = |
| 472 | 480 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -223,7 +223,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 223 | 223 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 224 | 224 | return invalidValue(l(ref || "object"), val, key, parent); |
| 225 | 225 | } |
| 226 | - const result: any = {}; | |
| 226 | + const result: any = Object.create(null); | |
| 227 | 227 | Object.getOwnPropertyNames(props).forEach(key => { |
| 228 | 228 | const prop = props[key]; |
| 229 | 229 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -234,7 +234,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 234 | 234 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 235 | 235 | } |
| 236 | 236 | }); |
| 237 | - return result; | |
| 237 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -217,7 +217,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 217 | 217 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 218 | 218 | return invalidValue(l(ref || "object"), val, key, parent); |
| 219 | 219 | } |
| 220 | - const result: any = {}; | |
| 220 | + const result: any = Object.create(null); | |
| 221 | 221 | Object.getOwnPropertyNames(props).forEach(key => { |
| 222 | 222 | const prop = props[key]; |
| 223 | 223 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -228,7 +228,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 228 | 228 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 229 | 229 | } |
| 230 | 230 | }); |
| 231 | - return result; | |
| 231 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f82d9.json
Melmdefault / QuickType.elm+8 −0
| @@ -365,6 +365,14 @@ encodeItems x = | ||
| 365 | 365 | |
| 366 | 366 | --- encoder helpers |
| 367 | 367 | |
| 368 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 369 | +makeDictEncoder f m r = | |
| 370 | + r | |
| 371 | + |> Dict.toList | |
| 372 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 373 | + |> String.join "," | |
| 374 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 375 | + | |
| 368 | 376 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 369 | 377 | makeNullableEncoder f m = |
| 370 | 378 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -192,7 +192,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 192 | 192 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 193 | 193 | return invalidValue(l(ref || "object"), val, key, parent); |
| 194 | 194 | } |
| 195 | - const result: any = {}; | |
| 195 | + const result: any = Object.create(null); | |
| 196 | 196 | Object.getOwnPropertyNames(props).forEach(key => { |
| 197 | 197 | const prop = props[key]; |
| 198 | 198 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -203,7 +203,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 203 | 203 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 204 | 204 | } |
| 205 | 205 | }); |
| 206 | - return result; | |
| 206 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -191,7 +191,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 191 | 191 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 192 | 192 | return invalidValue(l(ref || "object"), val, key, parent); |
| 193 | 193 | } |
| 194 | - const result: any = {}; | |
| 194 | + const result: any = Object.create(null); | |
| 195 | 195 | Object.getOwnPropertyNames(props).forEach(key => { |
| 196 | 196 | const prop = props[key]; |
| 197 | 197 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -202,7 +202,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 202 | 202 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 203 | 203 | } |
| 204 | 204 | }); |
| 205 | - return result; | |
| 205 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/f974d.json
Melmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickType x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/faff5.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeResponse x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/misc/fcca3.json
Melmdefault / QuickType.elm+8 −0
| @@ -819,6 +819,14 @@ encodeExpression x = | ||
| 819 | 819 | |
| 820 | 820 | --- encoder helpers |
| 821 | 821 | |
| 822 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 823 | +makeDictEncoder f m r = | |
| 824 | + r | |
| 825 | + |> Dict.toList | |
| 826 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 827 | + |> String.join "," | |
| 828 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 829 | + | |
| 822 | 830 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 823 | 831 | makeNullableEncoder f m = |
| 824 | 832 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -320,7 +320,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 320 | 320 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 321 | 321 | return invalidValue(l(ref || "object"), val, key, parent); |
| 322 | 322 | } |
| 323 | - const result: any = {}; | |
| 323 | + const result: any = Object.create(null); | |
| 324 | 324 | Object.getOwnPropertyNames(props).forEach(key => { |
| 325 | 325 | const prop = props[key]; |
| 326 | 326 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -331,7 +331,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 331 | 331 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 332 | 332 | } |
| 333 | 333 | }); |
| 334 | - return result; | |
| 334 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -317,7 +317,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 317 | 317 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 318 | 318 | return invalidValue(l(ref || "object"), val, key, parent); |
| 319 | 319 | } |
| 320 | - const result: any = {}; | |
| 320 | + const result: any = Object.create(null); | |
| 321 | 321 | Object.getOwnPropertyNames(props).forEach(key => { |
| 322 | 322 | const prop = props[key]; |
| 323 | 323 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -328,7 +328,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 328 | 328 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 329 | 329 | } |
| 330 | 330 | }); |
| 331 | - return result; | |
| 331 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/misc/fd329.json
Melmdefault / QuickType.elm+9 −1
| @@ -61,7 +61,7 @@ quickType = | ||
| 61 | 61 | encodeQuickType : QuickType -> Jenc.Value |
| 62 | 62 | encodeQuickType x = |
| 63 | 63 | Jenc.object |
| 64 | - [ ("data", Jenc.dict identity encodeDatum x.data) | |
| 64 | + [ ("data", makeDictEncoder identity encodeDatum x.data) | |
| 65 | 65 | , ("description", encodeDescription x.description) |
| 66 | 66 | ] |
| 67 | 67 | |
| @@ -97,6 +97,14 @@ encodeDescription x = | ||
| 97 | 97 | |
| 98 | 98 | --- encoder helpers |
| 99 | 99 | |
| 100 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 101 | +makeDictEncoder f m r = | |
| 102 | + r | |
| 103 | + |> Dict.toList | |
| 104 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 105 | + |> String.join "," | |
| 106 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 107 | + | |
| 100 | 108 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 101 | 109 | makeNullableEncoder f m = |
| 102 | 110 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/blns-object.json
Melmdefault / QuickType.elm+8 −0
| @@ -1847,6 +1847,14 @@ encodeC x = | ||
| 1847 | 1847 | |
| 1848 | 1848 | --- encoder helpers |
| 1849 | 1849 | |
| 1850 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1851 | +makeDictEncoder f m r = | |
| 1852 | + r | |
| 1853 | + |> Dict.toList | |
| 1854 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1855 | + |> String.join "," | |
| 1856 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1857 | + | |
| 1850 | 1858 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1851 | 1859 | makeNullableEncoder f m = |
| 1852 | 1860 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -702,7 +702,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 702 | 702 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 703 | 703 | return invalidValue(l(ref || "object"), val, key, parent); |
| 704 | 704 | } |
| 705 | - const result: any = {}; | |
| 705 | + const result: any = Object.create(null); | |
| 706 | 706 | Object.getOwnPropertyNames(props).forEach(key => { |
| 707 | 707 | const prop = props[key]; |
| 708 | 708 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -713,7 +713,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 713 | 713 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 714 | 714 | } |
| 715 | 715 | }); |
| 716 | - return result; | |
| 716 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -702,7 +702,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 702 | 702 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 703 | 703 | return invalidValue(l(ref || "object"), val, key, parent); |
| 704 | 704 | } |
| 705 | - const result: any = {}; | |
| 705 | + const result: any = Object.create(null); | |
| 706 | 706 | Object.getOwnPropertyNames(props).forEach(key => { |
| 707 | 707 | const prop = props[key]; |
| 708 | 708 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -713,7 +713,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 713 | 713 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 714 | 714 | } |
| 715 | 715 | }); |
| 716 | - return result; | |
| 716 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | if (typ === "any") return val; |
Test case
4 generated files · +17 −9test/inputs/json/priority/bug2037.json
Melmdefault / QuickType.elm+11 −3
| @@ -60,7 +60,7 @@ quickType = | ||
| 60 | 60 | encodeQuickType : QuickType -> Jenc.Value |
| 61 | 61 | encodeQuickType x = |
| 62 | 62 | Jenc.object |
| 63 | - [ ("mission_specs", Jenc.dict identity encodeMissionSpec x.missionSpecs) | |
| 63 | + [ ("mission_specs", makeDictEncoder identity encodeMissionSpec x.missionSpecs) | |
| 64 | 64 | ] |
| 65 | 65 | |
| 66 | 66 | missionSpec : Jdec.Decoder MissionSpec |
| @@ -71,7 +71,7 @@ missionSpec = | ||
| 71 | 71 | encodeMissionSpec : MissionSpec -> Jenc.Value |
| 72 | 72 | encodeMissionSpec x = |
| 73 | 73 | Jenc.object |
| 74 | - [ ("objectives", Jenc.dict identity encodeObjective x.objectives) | |
| 74 | + [ ("objectives", makeDictEncoder identity encodeObjective x.objectives) | |
| 75 | 75 | ] |
| 76 | 76 | |
| 77 | 77 | objective : Jdec.Decoder Objective |
| @@ -82,7 +82,7 @@ objective = | ||
| 82 | 82 | encodeObjective : Objective -> Jenc.Value |
| 83 | 83 | encodeObjective x = |
| 84 | 84 | Jenc.object |
| 85 | - [ ("rewards", Jenc.dict identity encodeReward x.rewards) | |
| 85 | + [ ("rewards", makeDictEncoder identity encodeReward x.rewards) | |
| 86 | 86 | ] |
| 87 | 87 | |
| 88 | 88 | reward : Jdec.Decoder Reward |
| @@ -97,6 +97,14 @@ encodeReward x = | ||
| 97 | 97 | |
| 98 | 98 | --- encoder helpers |
| 99 | 99 | |
| 100 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 101 | +makeDictEncoder f m r = | |
| 102 | + r | |
| 103 | + |> Dict.toList | |
| 104 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 105 | + |> String.join "," | |
| 106 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 107 | + | |
| 100 | 108 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 101 | 109 | makeNullableEncoder f m = |
| 102 | 110 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 119 | 119 | return invalidValue(l(ref || "object"), val, key, parent); |
| 120 | 120 | } |
| 121 | - const result: any = {}; | |
| 121 | + const result: any = Object.create(null); | |
| 122 | 122 | Object.getOwnPropertyNames(props).forEach(key => { |
| 123 | 123 | const prop = props[key]; |
| 124 | 124 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 130 | 130 | } |
| 131 | 131 | }); |
| 132 | - return result; | |
| 132 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/bug2521.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeOption x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/bug2590.json
Melmdefault / QuickType.elm+8 −0
| @@ -72,6 +72,14 @@ encodeInvoice x = | ||
| 72 | 72 | |
| 73 | 73 | --- encoder helpers |
| 74 | 74 | |
| 75 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 76 | +makeDictEncoder f m r = | |
| 77 | + r | |
| 78 | + |> Dict.toList | |
| 79 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 80 | + |> String.join "," | |
| 81 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 82 | + | |
| 75 | 83 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 76 | 84 | makeNullableEncoder f m = |
| 77 | 85 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/bug2663.json
Melmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickType x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/bug2793.json
Melmdefault / QuickType.elm+8 −0
| @@ -87,6 +87,14 @@ encodeLabels x = | ||
| 87 | 87 | |
| 88 | 88 | --- encoder helpers |
| 89 | 89 | |
| 90 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 91 | +makeDictEncoder f m r = | |
| 92 | + r | |
| 93 | + |> Dict.toList | |
| 94 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 95 | + |> String.join "," | |
| 96 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 97 | + | |
| 90 | 98 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 91 | 99 | makeNullableEncoder f m = |
| 92 | 100 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/json/priority/bug427.json
Mflowdefault / TopLevel.js+2 −2
| @@ -718,7 +718,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 718 | 718 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 719 | 719 | return invalidValue(l(ref || "object"), val, key, parent); |
| 720 | 720 | } |
| 721 | - const result: any = {}; | |
| 721 | + const result: any = Object.create(null); | |
| 722 | 722 | Object.getOwnPropertyNames(props).forEach(key => { |
| 723 | 723 | const prop = props[key]; |
| 724 | 724 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -729,7 +729,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 729 | 729 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 730 | 730 | } |
| 731 | 731 | }); |
| 732 | - return result; | |
| 732 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -664,7 +664,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 664 | 664 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 665 | 665 | return invalidValue(l(ref || "object"), val, key, parent); |
| 666 | 666 | } |
| 667 | - const result: any = {}; | |
| 667 | + const result: any = Object.create(null); | |
| 668 | 668 | Object.getOwnPropertyNames(props).forEach(key => { |
| 669 | 669 | const prop = props[key]; |
| 670 | 670 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -675,7 +675,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 675 | 675 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 676 | 676 | } |
| 677 | 677 | }); |
| 678 | - return result; | |
| 678 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/json/priority/bug790.json
Mflowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/priority/bug855-short.json
Melmdefault / QuickType.elm+9 −1
| @@ -45,7 +45,7 @@ quickType : Jdec.Decoder QuickType | ||
| 45 | 45 | quickType = Jdec.dict quickTypeValue |
| 46 | 46 | |
| 47 | 47 | quickTypeToString : QuickType -> String |
| 48 | -quickTypeToString r = Jenc.encode 0 (Jenc.dict identity encodeQuickTypeValue r) | |
| 48 | +quickTypeToString r = Jenc.encode 0 (makeDictEncoder identity encodeQuickTypeValue r) | |
| 49 | 49 | |
| 50 | 50 | quickTypeValue : Jdec.Decoder QuickTypeValue |
| 51 | 51 | quickTypeValue = |
| @@ -68,6 +68,14 @@ encodeQuickTypeValue x = | ||
| 68 | 68 | |
| 69 | 69 | --- encoder helpers |
| 70 | 70 | |
| 71 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 72 | +makeDictEncoder f m r = | |
| 73 | + r | |
| 74 | + |> Dict.toList | |
| 75 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 76 | + |> String.join "," | |
| 77 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 78 | + | |
| 71 | 79 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 72 | 80 | makeNullableEncoder f m = |
| 73 | 81 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/bug863.json
Melmdefault / QuickType.elm+8 −0
| @@ -374,6 +374,14 @@ encodeFluffyQuickType x = | ||
| 374 | 374 | |
| 375 | 375 | --- encoder helpers |
| 376 | 376 | |
| 377 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 378 | +makeDictEncoder f m r = | |
| 379 | + r | |
| 380 | + |> Dict.toList | |
| 381 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 382 | + |> String.join "," | |
| 383 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 384 | + | |
| 377 | 385 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 378 | 386 | makeNullableEncoder f m = |
| 379 | 387 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -193,7 +193,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 193 | 193 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 194 | 194 | return invalidValue(l(ref || "object"), val, key, parent); |
| 195 | 195 | } |
| 196 | - const result: any = {}; | |
| 196 | + const result: any = Object.create(null); | |
| 197 | 197 | Object.getOwnPropertyNames(props).forEach(key => { |
| 198 | 198 | const prop = props[key]; |
| 199 | 199 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -204,7 +204,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 204 | 204 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 205 | 205 | } |
| 206 | 206 | }); |
| 207 | - return result; | |
| 207 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -177,7 +177,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 177 | 177 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 178 | 178 | return invalidValue(l(ref || "object"), val, key, parent); |
| 179 | 179 | } |
| 180 | - const result: any = {}; | |
| 180 | + const result: any = Object.create(null); | |
| 181 | 181 | Object.getOwnPropertyNames(props).forEach(key => { |
| 182 | 182 | const prop = props[key]; |
| 183 | 183 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -188,7 +188,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 188 | 188 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 189 | 189 | } |
| 190 | 190 | }); |
| 191 | - return result; | |
| 191 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/priority/coin-pairs.json
Melmdefault / QuickType.elm+9 −1
| @@ -59,7 +59,7 @@ quickType = | ||
| 59 | 59 | encodeQuickType : QuickType -> Jenc.Value |
| 60 | 60 | encodeQuickType x = |
| 61 | 61 | Jenc.object |
| 62 | - [ ("pairs", Jenc.dict identity encodePair x.pairs) | |
| 62 | + [ ("pairs", makeDictEncoder identity encodePair x.pairs) | |
| 63 | 63 | , ("server_time", Jenc.int x.serverTime) |
| 64 | 64 | ] |
| 65 | 65 | |
| @@ -90,6 +90,14 @@ encodePair x = | ||
| 90 | 90 | |
| 91 | 91 | --- encoder helpers |
| 92 | 92 | |
| 93 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 94 | +makeDictEncoder f m r = | |
| 95 | + r | |
| 96 | + |> Dict.toList | |
| 97 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 98 | + |> String.join "," | |
| 99 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 100 | + | |
| 93 | 101 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 94 | 102 | makeNullableEncoder f m = |
| 95 | 103 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Test case
22 generated files · +74 −58test/inputs/json/priority/combinations1.json
Melmarray-type-array--eed288b23e27 / QuickType.elm+17 −9
| @@ -642,7 +642,7 @@ encodeQuickType x = | ||
| 642 | 642 | , ("fuzzy", Jenc.array encodeFuzzy x.fuzzy) |
| 643 | 643 | , ("gardenwards", Jenc.array encodeGardenward x.gardenwards) |
| 644 | 644 | , ("generalissimo", Jenc.array encodeGeneralissimo x.generalissimo) |
| 645 | - , ("habeas", Jenc.array (makeNullableEncoder (Jenc.dict identity Jenc.int)) x.habeas) | |
| 645 | + , ("habeas", Jenc.array (makeNullableEncoder (makeDictEncoder identity Jenc.int)) x.habeas) | |
| 646 | 646 | , ("hemicrystalline", Jenc.array encodeHemicrystalline x.hemicrystalline) |
| 647 | 647 | , ("hemocoele", Jenc.array encodeHemocoeleElement x.hemocoele) |
| 648 | 648 | , ("hoister", Jenc.array encodeHoister x.hoister) |
| @@ -916,7 +916,7 @@ consilience = | ||
| 916 | 916 | encodeConsilience : Consilience -> Jenc.Value |
| 917 | 917 | encodeConsilience x = case x of |
| 918 | 918 | DoubleInConsilience y -> Jenc.float y |
| 919 | - IntegerMapInConsilience y -> Jenc.dict identity Jenc.int y | |
| 919 | + IntegerMapInConsilience y -> makeDictEncoder identity Jenc.int y | |
| 920 | 920 | |
| 921 | 921 | constructor : Jdec.Decoder Constructor |
| 922 | 922 | constructor = |
| @@ -928,7 +928,7 @@ constructor = | ||
| 928 | 928 | encodeConstructor : Constructor -> Jenc.Value |
| 929 | 929 | encodeConstructor x = case x of |
| 930 | 930 | BoolInConstructor y -> Jenc.bool y |
| 931 | - UnionMapInConstructor y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 931 | + UnionMapInConstructor y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 932 | 932 | |
| 933 | 933 | continuative : Jdec.Decoder Continuative |
| 934 | 934 | continuative = |
| @@ -940,7 +940,7 @@ continuative = | ||
| 940 | 940 | encodeContinuative : Continuative -> Jenc.Value |
| 941 | 941 | encodeContinuative x = case x of |
| 942 | 942 | StringInContinuative y -> Jenc.string y |
| 943 | - IntegerMapInContinuative y -> Jenc.dict identity Jenc.int y | |
| 943 | + IntegerMapInContinuative y -> makeDictEncoder identity Jenc.int y | |
| 944 | 944 | |
| 945 | 945 | credulityElement : Jdec.Decoder CredulityElement |
| 946 | 946 | credulityElement = |
| @@ -1017,7 +1017,7 @@ encodeCreviced : Creviced -> Jenc.Value | ||
| 1017 | 1017 | encodeCreviced x = case x of |
| 1018 | 1018 | BoolInCreviced y -> Jenc.bool y |
| 1019 | 1019 | StringInCreviced y -> Jenc.string y |
| 1020 | - IntegerMapInCreviced y -> Jenc.dict identity Jenc.int y | |
| 1020 | + IntegerMapInCreviced y -> makeDictEncoder identity Jenc.int y | |
| 1021 | 1021 | |
| 1022 | 1022 | deruralizeElement : Jdec.Decoder DeruralizeElement |
| 1023 | 1023 | deruralizeElement = |
| @@ -1171,7 +1171,7 @@ encodeEleutheromania : Eleutheromania -> Jenc.Value | ||
| 1171 | 1171 | encodeEleutheromania x = case x of |
| 1172 | 1172 | StringInEleutheromania y -> Jenc.string y |
| 1173 | 1173 | DoubleInEleutheromania y -> Jenc.float y |
| 1174 | - IntegerMapInEleutheromania y -> Jenc.dict identity Jenc.int y | |
| 1174 | + IntegerMapInEleutheromania y -> makeDictEncoder identity Jenc.int y | |
| 1175 | 1175 | |
| 1176 | 1176 | encrust : Jdec.Decoder Encrust |
| 1177 | 1177 | encrust = |
| @@ -1469,7 +1469,7 @@ fuzzy = | ||
| 1469 | 1469 | encodeFuzzy : Fuzzy -> Jenc.Value |
| 1470 | 1470 | encodeFuzzy x = case x of |
| 1471 | 1471 | IntegerInFuzzy y -> Jenc.int y |
| 1472 | - UnionMapInFuzzy y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1472 | + UnionMapInFuzzy y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1473 | 1473 | |
| 1474 | 1474 | gardenward : Jdec.Decoder Gardenward |
| 1475 | 1475 | gardenward = |
| @@ -1497,7 +1497,7 @@ encodeGeneralissimo : Generalissimo -> Jenc.Value | ||
| 1497 | 1497 | encodeGeneralissimo x = case x of |
| 1498 | 1498 | BoolInGeneralissimo y -> Jenc.bool y |
| 1499 | 1499 | NullInGeneralissimo -> Jenc.null |
| 1500 | - IntegerMapInGeneralissimo y -> Jenc.dict identity Jenc.int y | |
| 1500 | + IntegerMapInGeneralissimo y -> makeDictEncoder identity Jenc.int y | |
| 1501 | 1501 | |
| 1502 | 1502 | hemicrystalline : Jdec.Decoder Hemicrystalline |
| 1503 | 1503 | hemicrystalline = |
| @@ -1695,10 +1695,18 @@ jacutinga = | ||
| 1695 | 1695 | encodeJacutinga : Jacutinga -> Jenc.Value |
| 1696 | 1696 | encodeJacutinga x = case x of |
| 1697 | 1697 | IntegerArrayInJacutinga y -> Jenc.array Jenc.int y |
| 1698 | - UnionMapInJacutinga y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1698 | + UnionMapInJacutinga y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1699 | 1699 | |
| 1700 | 1700 | --- encoder helpers |
| 1701 | 1701 | |
| 1702 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1703 | +makeDictEncoder f m r = | |
| 1704 | + r | |
| 1705 | + |> Dict.toList | |
| 1706 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1707 | + |> String.join "," | |
| 1708 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1709 | + | |
| 1702 | 1710 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1703 | 1711 | makeNullableEncoder f m = |
| 1704 | 1712 | case m of |
Melmdefault / QuickType.elm+17 −9
| @@ -641,7 +641,7 @@ encodeQuickType x = | ||
| 641 | 641 | , ("fuzzy", Jenc.list encodeFuzzy x.fuzzy) |
| 642 | 642 | , ("gardenwards", Jenc.list encodeGardenward x.gardenwards) |
| 643 | 643 | , ("generalissimo", Jenc.list encodeGeneralissimo x.generalissimo) |
| 644 | - , ("habeas", Jenc.list (makeNullableEncoder (Jenc.dict identity Jenc.int)) x.habeas) | |
| 644 | + , ("habeas", Jenc.list (makeNullableEncoder (makeDictEncoder identity Jenc.int)) x.habeas) | |
| 645 | 645 | , ("hemicrystalline", Jenc.list encodeHemicrystalline x.hemicrystalline) |
| 646 | 646 | , ("hemocoele", Jenc.list encodeHemocoeleElement x.hemocoele) |
| 647 | 647 | , ("hoister", Jenc.list encodeHoister x.hoister) |
| @@ -915,7 +915,7 @@ consilience = | ||
| 915 | 915 | encodeConsilience : Consilience -> Jenc.Value |
| 916 | 916 | encodeConsilience x = case x of |
| 917 | 917 | DoubleInConsilience y -> Jenc.float y |
| 918 | - IntegerMapInConsilience y -> Jenc.dict identity Jenc.int y | |
| 918 | + IntegerMapInConsilience y -> makeDictEncoder identity Jenc.int y | |
| 919 | 919 | |
| 920 | 920 | constructor : Jdec.Decoder Constructor |
| 921 | 921 | constructor = |
| @@ -927,7 +927,7 @@ constructor = | ||
| 927 | 927 | encodeConstructor : Constructor -> Jenc.Value |
| 928 | 928 | encodeConstructor x = case x of |
| 929 | 929 | BoolInConstructor y -> Jenc.bool y |
| 930 | - UnionMapInConstructor y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 930 | + UnionMapInConstructor y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 931 | 931 | |
| 932 | 932 | continuative : Jdec.Decoder Continuative |
| 933 | 933 | continuative = |
| @@ -939,7 +939,7 @@ continuative = | ||
| 939 | 939 | encodeContinuative : Continuative -> Jenc.Value |
| 940 | 940 | encodeContinuative x = case x of |
| 941 | 941 | StringInContinuative y -> Jenc.string y |
| 942 | - IntegerMapInContinuative y -> Jenc.dict identity Jenc.int y | |
| 942 | + IntegerMapInContinuative y -> makeDictEncoder identity Jenc.int y | |
| 943 | 943 | |
| 944 | 944 | credulityElement : Jdec.Decoder CredulityElement |
| 945 | 945 | credulityElement = |
| @@ -1016,7 +1016,7 @@ encodeCreviced : Creviced -> Jenc.Value | ||
| 1016 | 1016 | encodeCreviced x = case x of |
| 1017 | 1017 | BoolInCreviced y -> Jenc.bool y |
| 1018 | 1018 | StringInCreviced y -> Jenc.string y |
| 1019 | - IntegerMapInCreviced y -> Jenc.dict identity Jenc.int y | |
| 1019 | + IntegerMapInCreviced y -> makeDictEncoder identity Jenc.int y | |
| 1020 | 1020 | |
| 1021 | 1021 | deruralizeElement : Jdec.Decoder DeruralizeElement |
| 1022 | 1022 | deruralizeElement = |
| @@ -1170,7 +1170,7 @@ encodeEleutheromania : Eleutheromania -> Jenc.Value | ||
| 1170 | 1170 | encodeEleutheromania x = case x of |
| 1171 | 1171 | StringInEleutheromania y -> Jenc.string y |
| 1172 | 1172 | DoubleInEleutheromania y -> Jenc.float y |
| 1173 | - IntegerMapInEleutheromania y -> Jenc.dict identity Jenc.int y | |
| 1173 | + IntegerMapInEleutheromania y -> makeDictEncoder identity Jenc.int y | |
| 1174 | 1174 | |
| 1175 | 1175 | encrust : Jdec.Decoder Encrust |
| 1176 | 1176 | encrust = |
| @@ -1468,7 +1468,7 @@ fuzzy = | ||
| 1468 | 1468 | encodeFuzzy : Fuzzy -> Jenc.Value |
| 1469 | 1469 | encodeFuzzy x = case x of |
| 1470 | 1470 | IntegerInFuzzy y -> Jenc.int y |
| 1471 | - UnionMapInFuzzy y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1471 | + UnionMapInFuzzy y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1472 | 1472 | |
| 1473 | 1473 | gardenward : Jdec.Decoder Gardenward |
| 1474 | 1474 | gardenward = |
| @@ -1496,7 +1496,7 @@ encodeGeneralissimo : Generalissimo -> Jenc.Value | ||
| 1496 | 1496 | encodeGeneralissimo x = case x of |
| 1497 | 1497 | BoolInGeneralissimo y -> Jenc.bool y |
| 1498 | 1498 | NullInGeneralissimo -> Jenc.null |
| 1499 | - IntegerMapInGeneralissimo y -> Jenc.dict identity Jenc.int y | |
| 1499 | + IntegerMapInGeneralissimo y -> makeDictEncoder identity Jenc.int y | |
| 1500 | 1500 | |
| 1501 | 1501 | hemicrystalline : Jdec.Decoder Hemicrystalline |
| 1502 | 1502 | hemicrystalline = |
| @@ -1694,10 +1694,18 @@ jacutinga = | ||
| 1694 | 1694 | encodeJacutinga : Jacutinga -> Jenc.Value |
| 1695 | 1695 | encodeJacutinga x = case x of |
| 1696 | 1696 | IntegerArrayInJacutinga y -> Jenc.list Jenc.int y |
| 1697 | - UnionMapInJacutinga y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1697 | + UnionMapInJacutinga y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1698 | 1698 | |
| 1699 | 1699 | --- encoder helpers |
| 1700 | 1700 | |
| 1701 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1702 | +makeDictEncoder f m r = | |
| 1703 | + r | |
| 1704 | + |> Dict.toList | |
| 1705 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1706 | + |> String.join "," | |
| 1707 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1708 | + | |
| 1701 | 1709 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1702 | 1710 | makeNullableEncoder f m = |
| 1703 | 1711 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mflownice-property-names-true--f4d7920ee2ce / TopLevel.js+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mflowprefer-unions-false--a5053c0a486d / TopLevel.js+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mflowprefer-unknown-false--f1ab9e45d823 / TopLevel.js+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mflowruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = val[key]; |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mjavascriptconverters-top-level--67aa452ed509 / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptraw-type-any--474b307c39db / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = val[key]; |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptacronym-style-pascal--d9e0c1bd777a / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptconverters-all-objects--3a443babd1cb / TopLevel.ts+2 −2
| @@ -603,7 +603,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 603 | 603 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 604 | 604 | return invalidValue(l(ref || "object"), val, key, parent); |
| 605 | 605 | } |
| 606 | - const result: any = {}; | |
| 606 | + const result: any = Object.create(null); | |
| 607 | 607 | Object.getOwnPropertyNames(props).forEach(key => { |
| 608 | 608 | const prop = props[key]; |
| 609 | 609 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -614,7 +614,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 614 | 614 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 615 | 615 | } |
| 616 | 616 | }); |
| 617 | - return result; | |
| 617 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptnice-property-names-true--f4d7920ee2ce / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptprefer-const-values-true--6b26e4d1265c / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptprefer-types-true--df33e18681f9 / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptprefer-unions-false--a5053c0a486d / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptprefer-unknown-false--f1ab9e45d823 / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptraw-type-any--474b307c39db / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptreadonly-true--24da4fc107df / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Mtypescriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.ts+2 −2
| @@ -499,7 +499,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 499 | 499 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 500 | 500 | return invalidValue(l(ref || "object"), val, key, parent); |
| 501 | 501 | } |
| 502 | - const result: any = {}; | |
| 502 | + const result: any = Object.create(null); | |
| 503 | 503 | Object.getOwnPropertyNames(props).forEach(key => { |
| 504 | 504 | const prop = props[key]; |
| 505 | 505 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -510,7 +510,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 510 | 510 | result[key] = val[key]; |
| 511 | 511 | } |
| 512 | 512 | }); |
| 513 | - return result; | |
| 513 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if (typ === "any") return val; |
Test case
22 generated files · +80 −64test/inputs/json/priority/combinations2.json
Melmarray-type-array--eed288b23e27 / QuickType.elm+20 −12
| @@ -579,13 +579,13 @@ encodeQuickType x = | ||
| 579 | 579 | , ("amphithyron", Jenc.array (makeNullableEncoder encodeAmphithyron) x.amphithyron) |
| 580 | 580 | , ("Andriana", Jenc.array (makeNullableEncoder Jenc.string) x.andriana) |
| 581 | 581 | , ("ankee", Jenc.array encodeAnkeeElement x.ankee) |
| 582 | - , ("annihilator", Jenc.array (makeNullableEncoder (Jenc.dict identity (makeNullableEncoder Jenc.int))) x.annihilator) | |
| 582 | + , ("annihilator", Jenc.array (makeNullableEncoder (makeDictEncoder identity (makeNullableEncoder Jenc.int))) x.annihilator) | |
| 583 | 583 | , ("annulose", always Jenc.null x.annulose) |
| 584 | 584 | , ("Ansarie", Jenc.array encodeAnsarieElement x.ansarie) |
| 585 | 585 | , ("aphasia", Jenc.array encodeAphasia x.aphasia) |
| 586 | 586 | , ("asprawl", Jenc.array encodeAsprawl x.asprawl) |
| 587 | 587 | , ("attractive", Jenc.array (makeNullableEncoder Jenc.bool) x.attractive) |
| 588 | - , ("barksome", Jenc.dict identity Jenc.int x.barksome) | |
| 588 | + , ("barksome", makeDictEncoder identity Jenc.int x.barksome) | |
| 589 | 589 | , ("bedesman", Jenc.array encodeBedesman x.bedesman) |
| 590 | 590 | , ("belard", Jenc.array encodeBelard x.belard) |
| 591 | 591 | , ("bocking", Jenc.array encodeBocking x.bocking) |
| @@ -612,7 +612,7 @@ encodeQuickType x = | ||
| 612 | 612 | , ("School", Jenc.array encodeSchool x.school) |
| 613 | 613 | , ("Shakespearolater", Jenc.array encodeShakespearolater x.shakespearolater) |
| 614 | 614 | , ("Svan", Jenc.array Jenc.float x.svan) |
| 615 | - , ("Wayao", Jenc.dict identity Jenc.float x.wayao) | |
| 615 | + , ("Wayao", makeDictEncoder identity Jenc.float x.wayao) | |
| 616 | 616 | ] |
| 617 | 617 | |
| 618 | 618 | abranchiata : Jdec.Decoder Abranchiata |
| @@ -641,7 +641,7 @@ encodeAcademe : Academe -> Jenc.Value | ||
| 641 | 641 | encodeAcademe x = case x of |
| 642 | 642 | IntegerArrayInAcademe y -> Jenc.array Jenc.int y |
| 643 | 643 | IntegerInAcademe y -> Jenc.int y |
| 644 | - IntegerMapInAcademe y -> Jenc.dict identity Jenc.int y | |
| 644 | + IntegerMapInAcademe y -> makeDictEncoder identity Jenc.int y | |
| 645 | 645 | |
| 646 | 646 | acquirable : Jdec.Decoder Acquirable |
| 647 | 647 | acquirable = |
| @@ -653,7 +653,7 @@ acquirable = | ||
| 653 | 653 | encodeAcquirable : Acquirable -> Jenc.Value |
| 654 | 654 | encodeAcquirable x = case x of |
| 655 | 655 | UnionArrayInAcquirable y -> Jenc.array (makeNullableEncoder Jenc.int) y |
| 656 | - IntegerMapInAcquirable y -> Jenc.dict identity Jenc.int y | |
| 656 | + IntegerMapInAcquirable y -> makeDictEncoder identity Jenc.int y | |
| 657 | 657 | |
| 658 | 658 | aerometry : Jdec.Decoder Aerometry |
| 659 | 659 | aerometry = |
| @@ -1034,7 +1034,7 @@ encodeBocking : Bocking -> Jenc.Value | ||
| 1034 | 1034 | encodeBocking x = case x of |
| 1035 | 1035 | IntegerArrayInBocking y -> Jenc.array Jenc.int y |
| 1036 | 1036 | BoolInBocking y -> Jenc.bool y |
| 1037 | - IntegerMapInBocking y -> Jenc.dict identity Jenc.int y | |
| 1037 | + IntegerMapInBocking y -> makeDictEncoder identity Jenc.int y | |
| 1038 | 1038 | |
| 1039 | 1039 | brawlingly : Jdec.Decoder Brawlingly |
| 1040 | 1040 | brawlingly = |
| @@ -1046,7 +1046,7 @@ brawlingly = | ||
| 1046 | 1046 | encodeBrawlingly : Brawlingly -> Jenc.Value |
| 1047 | 1047 | encodeBrawlingly x = case x of |
| 1048 | 1048 | NullArrayInBrawlingly y -> Jenc.array (always Jenc.null) y |
| 1049 | - UnionMapInBrawlingly y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1049 | + UnionMapInBrawlingly y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1050 | 1050 | |
| 1051 | 1051 | brookie : Jdec.Decoder Brookie |
| 1052 | 1052 | brookie = |
| @@ -1098,7 +1098,7 @@ encodeCatallactic : Catallactic -> Jenc.Value | ||
| 1098 | 1098 | encodeCatallactic x = case x of |
| 1099 | 1099 | NullArrayInCatallactic y -> Jenc.array (always Jenc.null) y |
| 1100 | 1100 | BoolInCatallactic y -> Jenc.bool y |
| 1101 | - IntegerMapInCatallactic y -> Jenc.dict identity Jenc.int y | |
| 1101 | + IntegerMapInCatallactic y -> makeDictEncoder identity Jenc.int y | |
| 1102 | 1102 | |
| 1103 | 1103 | cemental : Jdec.Decoder Cemental |
| 1104 | 1104 | cemental = |
| @@ -1112,7 +1112,7 @@ encodeCemental : Cemental -> Jenc.Value | ||
| 1112 | 1112 | encodeCemental x = case x of |
| 1113 | 1113 | IntegerArrayInCemental y -> Jenc.array Jenc.int y |
| 1114 | 1114 | DoubleInCemental y -> Jenc.float y |
| 1115 | - IntegerMapInCemental y -> Jenc.dict identity Jenc.int y | |
| 1115 | + IntegerMapInCemental y -> makeDictEncoder identity Jenc.int y | |
| 1116 | 1116 | |
| 1117 | 1117 | chytridiaceaeElement : Jdec.Decoder ChytridiaceaeElement |
| 1118 | 1118 | chytridiaceaeElement = |
| @@ -1284,7 +1284,7 @@ eupatorium = | ||
| 1284 | 1284 | encodeEupatorium : Eupatorium -> Jenc.Value |
| 1285 | 1285 | encodeEupatorium x = case x of |
| 1286 | 1286 | NullArrayInEupatorium y -> Jenc.array (always Jenc.null) y |
| 1287 | - IntegerMapInEupatorium y -> Jenc.dict identity Jenc.int y | |
| 1287 | + IntegerMapInEupatorium y -> makeDictEncoder identity Jenc.int y | |
| 1288 | 1288 | |
| 1289 | 1289 | gryphosaurusElement : Jdec.Decoder GryphosaurusElement |
| 1290 | 1290 | gryphosaurusElement = |
| @@ -1359,7 +1359,7 @@ koryak = | ||
| 1359 | 1359 | encodeKoryak : Koryak -> Jenc.Value |
| 1360 | 1360 | encodeKoryak x = case x of |
| 1361 | 1361 | StringInKoryak y -> Jenc.string y |
| 1362 | - UnionMapInKoryak y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1362 | + UnionMapInKoryak y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1363 | 1363 | |
| 1364 | 1364 | laviniaElement : Jdec.Decoder LaviniaElement |
| 1365 | 1365 | laviniaElement = |
| @@ -1547,7 +1547,7 @@ encodeSchool : School -> Jenc.Value | ||
| 1547 | 1547 | encodeSchool x = case x of |
| 1548 | 1548 | IntegerInSchool y -> Jenc.int y |
| 1549 | 1549 | NullInSchool -> Jenc.null |
| 1550 | - IntegerMapInSchool y -> Jenc.dict identity Jenc.int y | |
| 1550 | + IntegerMapInSchool y -> makeDictEncoder identity Jenc.int y | |
| 1551 | 1551 | |
| 1552 | 1552 | shakespearolater : Jdec.Decoder Shakespearolater |
| 1553 | 1553 | shakespearolater = |
| @@ -1565,6 +1565,14 @@ encodeShakespearolater x = case x of | ||
| 1565 | 1565 | |
| 1566 | 1566 | --- encoder helpers |
| 1567 | 1567 | |
| 1568 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1569 | +makeDictEncoder f m r = | |
| 1570 | + r | |
| 1571 | + |> Dict.toList | |
| 1572 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1573 | + |> String.join "," | |
| 1574 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1575 | + | |
| 1568 | 1576 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1569 | 1577 | makeNullableEncoder f m = |
| 1570 | 1578 | case m of |
Melmdefault / QuickType.elm+20 −12
| @@ -578,13 +578,13 @@ encodeQuickType x = | ||
| 578 | 578 | , ("amphithyron", Jenc.list (makeNullableEncoder encodeAmphithyron) x.amphithyron) |
| 579 | 579 | , ("Andriana", Jenc.list (makeNullableEncoder Jenc.string) x.andriana) |
| 580 | 580 | , ("ankee", Jenc.list encodeAnkeeElement x.ankee) |
| 581 | - , ("annihilator", Jenc.list (makeNullableEncoder (Jenc.dict identity (makeNullableEncoder Jenc.int))) x.annihilator) | |
| 581 | + , ("annihilator", Jenc.list (makeNullableEncoder (makeDictEncoder identity (makeNullableEncoder Jenc.int))) x.annihilator) | |
| 582 | 582 | , ("annulose", always Jenc.null x.annulose) |
| 583 | 583 | , ("Ansarie", Jenc.list encodeAnsarieElement x.ansarie) |
| 584 | 584 | , ("aphasia", Jenc.list encodeAphasia x.aphasia) |
| 585 | 585 | , ("asprawl", Jenc.list encodeAsprawl x.asprawl) |
| 586 | 586 | , ("attractive", Jenc.list (makeNullableEncoder Jenc.bool) x.attractive) |
| 587 | - , ("barksome", Jenc.dict identity Jenc.int x.barksome) | |
| 587 | + , ("barksome", makeDictEncoder identity Jenc.int x.barksome) | |
| 588 | 588 | , ("bedesman", Jenc.list encodeBedesman x.bedesman) |
| 589 | 589 | , ("belard", Jenc.list encodeBelard x.belard) |
| 590 | 590 | , ("bocking", Jenc.list encodeBocking x.bocking) |
| @@ -611,7 +611,7 @@ encodeQuickType x = | ||
| 611 | 611 | , ("School", Jenc.list encodeSchool x.school) |
| 612 | 612 | , ("Shakespearolater", Jenc.list encodeShakespearolater x.shakespearolater) |
| 613 | 613 | , ("Svan", Jenc.list Jenc.float x.svan) |
| 614 | - , ("Wayao", Jenc.dict identity Jenc.float x.wayao) | |
| 614 | + , ("Wayao", makeDictEncoder identity Jenc.float x.wayao) | |
| 615 | 615 | ] |
| 616 | 616 | |
| 617 | 617 | abranchiata : Jdec.Decoder Abranchiata |
| @@ -640,7 +640,7 @@ encodeAcademe : Academe -> Jenc.Value | ||
| 640 | 640 | encodeAcademe x = case x of |
| 641 | 641 | IntegerArrayInAcademe y -> Jenc.list Jenc.int y |
| 642 | 642 | IntegerInAcademe y -> Jenc.int y |
| 643 | - IntegerMapInAcademe y -> Jenc.dict identity Jenc.int y | |
| 643 | + IntegerMapInAcademe y -> makeDictEncoder identity Jenc.int y | |
| 644 | 644 | |
| 645 | 645 | acquirable : Jdec.Decoder Acquirable |
| 646 | 646 | acquirable = |
| @@ -652,7 +652,7 @@ acquirable = | ||
| 652 | 652 | encodeAcquirable : Acquirable -> Jenc.Value |
| 653 | 653 | encodeAcquirable x = case x of |
| 654 | 654 | UnionArrayInAcquirable y -> Jenc.list (makeNullableEncoder Jenc.int) y |
| 655 | - IntegerMapInAcquirable y -> Jenc.dict identity Jenc.int y | |
| 655 | + IntegerMapInAcquirable y -> makeDictEncoder identity Jenc.int y | |
| 656 | 656 | |
| 657 | 657 | aerometry : Jdec.Decoder Aerometry |
| 658 | 658 | aerometry = |
| @@ -1033,7 +1033,7 @@ encodeBocking : Bocking -> Jenc.Value | ||
| 1033 | 1033 | encodeBocking x = case x of |
| 1034 | 1034 | IntegerArrayInBocking y -> Jenc.list Jenc.int y |
| 1035 | 1035 | BoolInBocking y -> Jenc.bool y |
| 1036 | - IntegerMapInBocking y -> Jenc.dict identity Jenc.int y | |
| 1036 | + IntegerMapInBocking y -> makeDictEncoder identity Jenc.int y | |
| 1037 | 1037 | |
| 1038 | 1038 | brawlingly : Jdec.Decoder Brawlingly |
| 1039 | 1039 | brawlingly = |
| @@ -1045,7 +1045,7 @@ brawlingly = | ||
| 1045 | 1045 | encodeBrawlingly : Brawlingly -> Jenc.Value |
| 1046 | 1046 | encodeBrawlingly x = case x of |
| 1047 | 1047 | NullArrayInBrawlingly y -> Jenc.list (always Jenc.null) y |
| 1048 | - UnionMapInBrawlingly y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1048 | + UnionMapInBrawlingly y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1049 | 1049 | |
| 1050 | 1050 | brookie : Jdec.Decoder Brookie |
| 1051 | 1051 | brookie = |
| @@ -1097,7 +1097,7 @@ encodeCatallactic : Catallactic -> Jenc.Value | ||
| 1097 | 1097 | encodeCatallactic x = case x of |
| 1098 | 1098 | NullArrayInCatallactic y -> Jenc.list (always Jenc.null) y |
| 1099 | 1099 | BoolInCatallactic y -> Jenc.bool y |
| 1100 | - IntegerMapInCatallactic y -> Jenc.dict identity Jenc.int y | |
| 1100 | + IntegerMapInCatallactic y -> makeDictEncoder identity Jenc.int y | |
| 1101 | 1101 | |
| 1102 | 1102 | cemental : Jdec.Decoder Cemental |
| 1103 | 1103 | cemental = |
| @@ -1111,7 +1111,7 @@ encodeCemental : Cemental -> Jenc.Value | ||
| 1111 | 1111 | encodeCemental x = case x of |
| 1112 | 1112 | IntegerArrayInCemental y -> Jenc.list Jenc.int y |
| 1113 | 1113 | DoubleInCemental y -> Jenc.float y |
| 1114 | - IntegerMapInCemental y -> Jenc.dict identity Jenc.int y | |
| 1114 | + IntegerMapInCemental y -> makeDictEncoder identity Jenc.int y | |
| 1115 | 1115 | |
| 1116 | 1116 | chytridiaceaeElement : Jdec.Decoder ChytridiaceaeElement |
| 1117 | 1117 | chytridiaceaeElement = |
| @@ -1283,7 +1283,7 @@ eupatorium = | ||
| 1283 | 1283 | encodeEupatorium : Eupatorium -> Jenc.Value |
| 1284 | 1284 | encodeEupatorium x = case x of |
| 1285 | 1285 | NullArrayInEupatorium y -> Jenc.list (always Jenc.null) y |
| 1286 | - IntegerMapInEupatorium y -> Jenc.dict identity Jenc.int y | |
| 1286 | + IntegerMapInEupatorium y -> makeDictEncoder identity Jenc.int y | |
| 1287 | 1287 | |
| 1288 | 1288 | gryphosaurusElement : Jdec.Decoder GryphosaurusElement |
| 1289 | 1289 | gryphosaurusElement = |
| @@ -1358,7 +1358,7 @@ koryak = | ||
| 1358 | 1358 | encodeKoryak : Koryak -> Jenc.Value |
| 1359 | 1359 | encodeKoryak x = case x of |
| 1360 | 1360 | StringInKoryak y -> Jenc.string y |
| 1361 | - UnionMapInKoryak y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1361 | + UnionMapInKoryak y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1362 | 1362 | |
| 1363 | 1363 | laviniaElement : Jdec.Decoder LaviniaElement |
| 1364 | 1364 | laviniaElement = |
| @@ -1546,7 +1546,7 @@ encodeSchool : School -> Jenc.Value | ||
| 1546 | 1546 | encodeSchool x = case x of |
| 1547 | 1547 | IntegerInSchool y -> Jenc.int y |
| 1548 | 1548 | NullInSchool -> Jenc.null |
| 1549 | - IntegerMapInSchool y -> Jenc.dict identity Jenc.int y | |
| 1549 | + IntegerMapInSchool y -> makeDictEncoder identity Jenc.int y | |
| 1550 | 1550 | |
| 1551 | 1551 | shakespearolater : Jdec.Decoder Shakespearolater |
| 1552 | 1552 | shakespearolater = |
| @@ -1564,6 +1564,14 @@ encodeShakespearolater x = case x of | ||
| 1564 | 1564 | |
| 1565 | 1565 | --- encoder helpers |
| 1566 | 1566 | |
| 1567 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1568 | +makeDictEncoder f m r = | |
| 1569 | + r | |
| 1570 | + |> Dict.toList | |
| 1571 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1572 | + |> String.join "," | |
| 1573 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1574 | + | |
| 1567 | 1575 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1568 | 1576 | makeNullableEncoder f m = |
| 1569 | 1577 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mflownice-property-names-true--f4d7920ee2ce / TopLevel.js+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mflowprefer-unions-false--a5053c0a486d / TopLevel.js+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mflowprefer-unknown-false--f1ab9e45d823 / TopLevel.js+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mflowruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = val[key]; |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mjavascriptconverters-top-level--67aa452ed509 / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptraw-type-any--474b307c39db / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = val[key]; |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptacronym-style-pascal--d9e0c1bd777a / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptconverters-all-objects--3a443babd1cb / TopLevel.ts+2 −2
| @@ -531,7 +531,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 531 | 531 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 532 | 532 | return invalidValue(l(ref || "object"), val, key, parent); |
| 533 | 533 | } |
| 534 | - const result: any = {}; | |
| 534 | + const result: any = Object.create(null); | |
| 535 | 535 | Object.getOwnPropertyNames(props).forEach(key => { |
| 536 | 536 | const prop = props[key]; |
| 537 | 537 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -542,7 +542,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 542 | 542 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 543 | 543 | } |
| 544 | 544 | }); |
| 545 | - return result; | |
| 545 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptnice-property-names-true--f4d7920ee2ce / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptprefer-const-values-true--6b26e4d1265c / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptprefer-types-true--df33e18681f9 / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptprefer-unions-false--a5053c0a486d / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptprefer-unknown-false--f1ab9e45d823 / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptraw-type-any--474b307c39db / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptreadonly-true--24da4fc107df / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Mtypescriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.ts+2 −2
| @@ -451,7 +451,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 451 | 451 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 452 | 452 | return invalidValue(l(ref || "object"), val, key, parent); |
| 453 | 453 | } |
| 454 | - const result: any = {}; | |
| 454 | + const result: any = Object.create(null); | |
| 455 | 455 | Object.getOwnPropertyNames(props).forEach(key => { |
| 456 | 456 | const prop = props[key]; |
| 457 | 457 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -462,7 +462,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 462 | 462 | result[key] = val[key]; |
| 463 | 463 | } |
| 464 | 464 | }); |
| 465 | - return result; | |
| 465 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | if (typ === "any") return val; |
Test case
22 generated files · +70 −54test/inputs/json/priority/combinations3.json
Melmarray-type-array--eed288b23e27 / QuickType.elm+15 −7
| @@ -714,7 +714,7 @@ encodeQuickType x = | ||
| 714 | 714 | , ("prefreshman", Jenc.array encodePrefreshmanElement x.prefreshman) |
| 715 | 715 | , ("prehensility", Jenc.array encodePrehensility x.prehensility) |
| 716 | 716 | , ("prevoidance", Jenc.array encodePrevoidance x.prevoidance) |
| 717 | - , ("probant", Jenc.array (Jenc.dict identity (makeNullableEncoder Jenc.int)) x.probant) | |
| 717 | + , ("probant", Jenc.array (makeDictEncoder identity (makeNullableEncoder Jenc.int)) x.probant) | |
| 718 | 718 | , ("protext", Jenc.array encodeProtext x.protext) |
| 719 | 719 | ] |
| 720 | 720 | |
| @@ -789,7 +789,7 @@ kongoni = | ||
| 789 | 789 | encodeKongoni : Kongoni -> Jenc.Value |
| 790 | 790 | encodeKongoni x = case x of |
| 791 | 791 | IntegerArrayInKongoni y -> Jenc.array Jenc.int y |
| 792 | - IntegerMapInKongoni y -> Jenc.dict identity Jenc.int y | |
| 792 | + IntegerMapInKongoni y -> makeDictEncoder identity Jenc.int y | |
| 793 | 793 | |
| 794 | 794 | ladronismElement : Jdec.Decoder LadronismElement |
| 795 | 795 | ladronismElement = |
| @@ -1462,7 +1462,7 @@ paleographically = | ||
| 1462 | 1462 | encodePaleographically : Paleographically -> Jenc.Value |
| 1463 | 1463 | encodePaleographically x = case x of |
| 1464 | 1464 | DoubleInPaleographically y -> Jenc.float y |
| 1465 | - UnionMapInPaleographically y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1465 | + UnionMapInPaleographically y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1466 | 1466 | |
| 1467 | 1467 | pamphletwise : Jdec.Decoder Pamphletwise |
| 1468 | 1468 | pamphletwise = |
| @@ -1476,7 +1476,7 @@ encodePamphletwise : Pamphletwise -> Jenc.Value | ||
| 1476 | 1476 | encodePamphletwise x = case x of |
| 1477 | 1477 | IntegerInPamphletwise y -> Jenc.int y |
| 1478 | 1478 | StringInPamphletwise y -> Jenc.string y |
| 1479 | - IntegerMapInPamphletwise y -> Jenc.dict identity Jenc.int y | |
| 1479 | + IntegerMapInPamphletwise y -> makeDictEncoder identity Jenc.int y | |
| 1480 | 1480 | |
| 1481 | 1481 | pediatric : Jdec.Decoder Pediatric |
| 1482 | 1482 | pediatric = |
| @@ -1613,7 +1613,7 @@ placuntiti = | ||
| 1613 | 1613 | encodePlacuntiti : Placuntiti -> Jenc.Value |
| 1614 | 1614 | encodePlacuntiti x = case x of |
| 1615 | 1615 | IntegerInPlacuntiti y -> Jenc.int y |
| 1616 | - IntegerMapInPlacuntiti y -> Jenc.dict identity Jenc.int y | |
| 1616 | + IntegerMapInPlacuntiti y -> makeDictEncoder identity Jenc.int y | |
| 1617 | 1617 | |
| 1618 | 1618 | plectopterous : Jdec.Decoder Plectopterous |
| 1619 | 1619 | plectopterous = |
| @@ -1625,7 +1625,7 @@ plectopterous = | ||
| 1625 | 1625 | encodePlectopterous : Plectopterous -> Jenc.Value |
| 1626 | 1626 | encodePlectopterous x = case x of |
| 1627 | 1627 | DoubleInPlectopterous y -> Jenc.float y |
| 1628 | - IntegerMapInPlectopterous y -> Jenc.dict identity Jenc.int y | |
| 1628 | + IntegerMapInPlectopterous y -> makeDictEncoder identity Jenc.int y | |
| 1629 | 1629 | |
| 1630 | 1630 | pneumocele : Jdec.Decoder Pneumocele |
| 1631 | 1631 | pneumocele = |
| @@ -1710,7 +1710,7 @@ encodePoormaster : Poormaster -> Jenc.Value | ||
| 1710 | 1710 | encodePoormaster x = case x of |
| 1711 | 1711 | IntegerArrayInPoormaster y -> Jenc.array Jenc.int y |
| 1712 | 1712 | NullInPoormaster -> Jenc.null |
| 1713 | - IntegerMapInPoormaster y -> Jenc.dict identity Jenc.int y | |
| 1713 | + IntegerMapInPoormaster y -> makeDictEncoder identity Jenc.int y | |
| 1714 | 1714 | |
| 1715 | 1715 | potwhiskyElement : Jdec.Decoder PotwhiskyElement |
| 1716 | 1716 | potwhiskyElement = |
| @@ -1896,6 +1896,14 @@ encodeProtext x = case x of | ||
| 1896 | 1896 | |
| 1897 | 1897 | --- encoder helpers |
| 1898 | 1898 | |
| 1899 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1900 | +makeDictEncoder f m r = | |
| 1901 | + r | |
| 1902 | + |> Dict.toList | |
| 1903 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1904 | + |> String.join "," | |
| 1905 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1906 | + | |
| 1899 | 1907 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1900 | 1908 | makeNullableEncoder f m = |
| 1901 | 1909 | case m of |
Melmdefault / QuickType.elm+15 −7
| @@ -713,7 +713,7 @@ encodeQuickType x = | ||
| 713 | 713 | , ("prefreshman", Jenc.list encodePrefreshmanElement x.prefreshman) |
| 714 | 714 | , ("prehensility", Jenc.list encodePrehensility x.prehensility) |
| 715 | 715 | , ("prevoidance", Jenc.list encodePrevoidance x.prevoidance) |
| 716 | - , ("probant", Jenc.list (Jenc.dict identity (makeNullableEncoder Jenc.int)) x.probant) | |
| 716 | + , ("probant", Jenc.list (makeDictEncoder identity (makeNullableEncoder Jenc.int)) x.probant) | |
| 717 | 717 | , ("protext", Jenc.list encodeProtext x.protext) |
| 718 | 718 | ] |
| 719 | 719 | |
| @@ -788,7 +788,7 @@ kongoni = | ||
| 788 | 788 | encodeKongoni : Kongoni -> Jenc.Value |
| 789 | 789 | encodeKongoni x = case x of |
| 790 | 790 | IntegerArrayInKongoni y -> Jenc.list Jenc.int y |
| 791 | - IntegerMapInKongoni y -> Jenc.dict identity Jenc.int y | |
| 791 | + IntegerMapInKongoni y -> makeDictEncoder identity Jenc.int y | |
| 792 | 792 | |
| 793 | 793 | ladronismElement : Jdec.Decoder LadronismElement |
| 794 | 794 | ladronismElement = |
| @@ -1461,7 +1461,7 @@ paleographically = | ||
| 1461 | 1461 | encodePaleographically : Paleographically -> Jenc.Value |
| 1462 | 1462 | encodePaleographically x = case x of |
| 1463 | 1463 | DoubleInPaleographically y -> Jenc.float y |
| 1464 | - UnionMapInPaleographically y -> Jenc.dict identity (makeNullableEncoder Jenc.int) y | |
| 1464 | + UnionMapInPaleographically y -> makeDictEncoder identity (makeNullableEncoder Jenc.int) y | |
| 1465 | 1465 | |
| 1466 | 1466 | pamphletwise : Jdec.Decoder Pamphletwise |
| 1467 | 1467 | pamphletwise = |
| @@ -1475,7 +1475,7 @@ encodePamphletwise : Pamphletwise -> Jenc.Value | ||
| 1475 | 1475 | encodePamphletwise x = case x of |
| 1476 | 1476 | IntegerInPamphletwise y -> Jenc.int y |
| 1477 | 1477 | StringInPamphletwise y -> Jenc.string y |
| 1478 | - IntegerMapInPamphletwise y -> Jenc.dict identity Jenc.int y | |
| 1478 | + IntegerMapInPamphletwise y -> makeDictEncoder identity Jenc.int y | |
| 1479 | 1479 | |
| 1480 | 1480 | pediatric : Jdec.Decoder Pediatric |
| 1481 | 1481 | pediatric = |
| @@ -1612,7 +1612,7 @@ placuntiti = | ||
| 1612 | 1612 | encodePlacuntiti : Placuntiti -> Jenc.Value |
| 1613 | 1613 | encodePlacuntiti x = case x of |
| 1614 | 1614 | IntegerInPlacuntiti y -> Jenc.int y |
| 1615 | - IntegerMapInPlacuntiti y -> Jenc.dict identity Jenc.int y | |
| 1615 | + IntegerMapInPlacuntiti y -> makeDictEncoder identity Jenc.int y | |
| 1616 | 1616 | |
| 1617 | 1617 | plectopterous : Jdec.Decoder Plectopterous |
| 1618 | 1618 | plectopterous = |
| @@ -1624,7 +1624,7 @@ plectopterous = | ||
| 1624 | 1624 | encodePlectopterous : Plectopterous -> Jenc.Value |
| 1625 | 1625 | encodePlectopterous x = case x of |
| 1626 | 1626 | DoubleInPlectopterous y -> Jenc.float y |
| 1627 | - IntegerMapInPlectopterous y -> Jenc.dict identity Jenc.int y | |
| 1627 | + IntegerMapInPlectopterous y -> makeDictEncoder identity Jenc.int y | |
| 1628 | 1628 | |
| 1629 | 1629 | pneumocele : Jdec.Decoder Pneumocele |
| 1630 | 1630 | pneumocele = |
| @@ -1709,7 +1709,7 @@ encodePoormaster : Poormaster -> Jenc.Value | ||
| 1709 | 1709 | encodePoormaster x = case x of |
| 1710 | 1710 | IntegerArrayInPoormaster y -> Jenc.list Jenc.int y |
| 1711 | 1711 | NullInPoormaster -> Jenc.null |
| 1712 | - IntegerMapInPoormaster y -> Jenc.dict identity Jenc.int y | |
| 1712 | + IntegerMapInPoormaster y -> makeDictEncoder identity Jenc.int y | |
| 1713 | 1713 | |
| 1714 | 1714 | potwhiskyElement : Jdec.Decoder PotwhiskyElement |
| 1715 | 1715 | potwhiskyElement = |
| @@ -1895,6 +1895,14 @@ encodeProtext x = case x of | ||
| 1895 | 1895 | |
| 1896 | 1896 | --- encoder helpers |
| 1897 | 1897 | |
| 1898 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1899 | +makeDictEncoder f m r = | |
| 1900 | + r | |
| 1901 | + |> Dict.toList | |
| 1902 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1903 | + |> String.join "," | |
| 1904 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1905 | + | |
| 1898 | 1906 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1899 | 1907 | makeNullableEncoder f m = |
| 1900 | 1908 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mflownice-property-names-true--f4d7920ee2ce / TopLevel.js+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mflowprefer-unions-false--a5053c0a486d / TopLevel.js+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mflowprefer-unknown-false--f1ab9e45d823 / TopLevel.js+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mflowruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = val[key]; |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mjavascriptconverters-top-level--67aa452ed509 / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptraw-type-any--474b307c39db / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = val[key]; |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptacronym-style-pascal--d9e0c1bd777a / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptconverters-all-objects--3a443babd1cb / TopLevel.ts+2 −2
| @@ -667,7 +667,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 667 | 667 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 668 | 668 | return invalidValue(l(ref || "object"), val, key, parent); |
| 669 | 669 | } |
| 670 | - const result: any = {}; | |
| 670 | + const result: any = Object.create(null); | |
| 671 | 671 | Object.getOwnPropertyNames(props).forEach(key => { |
| 672 | 672 | const prop = props[key]; |
| 673 | 673 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -678,7 +678,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 678 | 678 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 679 | 679 | } |
| 680 | 680 | }); |
| 681 | - return result; | |
| 681 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptnice-property-names-true--f4d7920ee2ce / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptprefer-const-values-true--6b26e4d1265c / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptprefer-types-true--df33e18681f9 / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptprefer-unions-false--a5053c0a486d / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptprefer-unknown-false--f1ab9e45d823 / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptraw-type-any--474b307c39db / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptreadonly-true--24da4fc107df / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Mtypescriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.ts+2 −2
| @@ -555,7 +555,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 555 | 555 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 556 | 556 | return invalidValue(l(ref || "object"), val, key, parent); |
| 557 | 557 | } |
| 558 | - const result: any = {}; | |
| 558 | + const result: any = Object.create(null); | |
| 559 | 559 | Object.getOwnPropertyNames(props).forEach(key => { |
| 560 | 560 | const prop = props[key]; |
| 561 | 561 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -566,7 +566,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 566 | 566 | result[key] = val[key]; |
| 567 | 567 | } |
| 568 | 568 | }); |
| 569 | - return result; | |
| 569 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | if (typ === "any") return val; |
Test case
22 generated files · +78 −62test/inputs/json/priority/combinations4.json
Melmarray-type-array--eed288b23e27 / QuickType.elm+19 −11
| @@ -830,7 +830,7 @@ encodeQuickType x = | ||
| 830 | 830 | , ("untasked", Jenc.array encodeUntasked x.untasked) |
| 831 | 831 | , ("unvarying", Jenc.array encodeUnvarying x.unvarying) |
| 832 | 832 | , ("vehemently", Jenc.array encodeVehemently x.vehemently) |
| 833 | - , ("warriorship", Jenc.dict identity Jenc.bool x.warriorship) | |
| 833 | + , ("warriorship", makeDictEncoder identity Jenc.bool x.warriorship) | |
| 834 | 834 | , ("whitepot", Jenc.array encodeWhitepot x.whitepot) |
| 835 | 835 | , ("wrothy", Jenc.array encodeWrothyElement x.wrothy) |
| 836 | 836 | ] |
| @@ -1014,7 +1014,7 @@ querier = | ||
| 1014 | 1014 | encodeQuerier : Querier -> Jenc.Value |
| 1015 | 1015 | encodeQuerier x = case x of |
| 1016 | 1016 | BoolInQuerier y -> Jenc.bool y |
| 1017 | - IntegerMapInQuerier y -> Jenc.dict identity Jenc.int y | |
| 1017 | + IntegerMapInQuerier y -> makeDictEncoder identity Jenc.int y | |
| 1018 | 1018 | |
| 1019 | 1019 | rebarbative : Jdec.Decoder Rebarbative |
| 1020 | 1020 | rebarbative = |
| @@ -1312,7 +1312,7 @@ encodeSaprophilous : Saprophilous -> Jenc.Value | ||
| 1312 | 1312 | encodeSaprophilous x = case x of |
| 1313 | 1313 | NullInSaprophilous -> Jenc.null |
| 1314 | 1314 | StringInSaprophilous y -> Jenc.string y |
| 1315 | - IntegerMapInSaprophilous y -> Jenc.dict identity Jenc.int y | |
| 1315 | + IntegerMapInSaprophilous y -> makeDictEncoder identity Jenc.int y | |
| 1316 | 1316 | |
| 1317 | 1317 | saxtenElement : Jdec.Decoder SaxtenElement |
| 1318 | 1318 | saxtenElement = |
| @@ -1446,7 +1446,7 @@ encodeScoffer : Scoffer -> Jenc.Value | ||
| 1446 | 1446 | encodeScoffer x = case x of |
| 1447 | 1447 | NullArrayInScoffer y -> Jenc.array (always Jenc.null) y |
| 1448 | 1448 | NullInScoffer -> Jenc.null |
| 1449 | - IntegerMapInScoffer y -> Jenc.dict identity Jenc.int y | |
| 1449 | + IntegerMapInScoffer y -> makeDictEncoder identity Jenc.int y | |
| 1450 | 1450 | |
| 1451 | 1451 | scrampum : Jdec.Decoder Scrampum |
| 1452 | 1452 | scrampum = |
| @@ -1632,7 +1632,7 @@ encodeStimulability : Stimulability -> Jenc.Value | ||
| 1632 | 1632 | encodeStimulability x = case x of |
| 1633 | 1633 | BoolInStimulability y -> Jenc.bool y |
| 1634 | 1634 | IntegerInStimulability y -> Jenc.int y |
| 1635 | - IntegerMapInStimulability y -> Jenc.dict identity Jenc.int y | |
| 1635 | + IntegerMapInStimulability y -> makeDictEncoder identity Jenc.int y | |
| 1636 | 1636 | |
| 1637 | 1637 | strangleable : Jdec.Decoder Strangleable |
| 1638 | 1638 | strangleable = |
| @@ -1852,7 +1852,7 @@ encodeUnbeginning : Unbeginning -> Jenc.Value | ||
| 1852 | 1852 | encodeUnbeginning x = case x of |
| 1853 | 1853 | NullArrayInUnbeginning y -> Jenc.array (always Jenc.null) y |
| 1854 | 1854 | StringInUnbeginning y -> Jenc.string y |
| 1855 | - IntegerMapInUnbeginning y -> Jenc.dict identity Jenc.int y | |
| 1855 | + IntegerMapInUnbeginning y -> makeDictEncoder identity Jenc.int y | |
| 1856 | 1856 | |
| 1857 | 1857 | undesirability : Jdec.Decoder Undesirability |
| 1858 | 1858 | undesirability = |
| @@ -1866,7 +1866,7 @@ encodeUndesirability : Undesirability -> Jenc.Value | ||
| 1866 | 1866 | encodeUndesirability x = case x of |
| 1867 | 1867 | IntegerArrayInUndesirability y -> Jenc.array Jenc.int y |
| 1868 | 1868 | StringInUndesirability y -> Jenc.string y |
| 1869 | - IntegerMapInUndesirability y -> Jenc.dict identity Jenc.int y | |
| 1869 | + IntegerMapInUndesirability y -> makeDictEncoder identity Jenc.int y | |
| 1870 | 1870 | |
| 1871 | 1871 | unerasing : Jdec.Decoder Unerasing |
| 1872 | 1872 | unerasing = |
| @@ -1880,7 +1880,7 @@ encodeUnerasing : Unerasing -> Jenc.Value | ||
| 1880 | 1880 | encodeUnerasing x = case x of |
| 1881 | 1881 | NullArrayInUnerasing y -> Jenc.array (always Jenc.null) y |
| 1882 | 1882 | IntegerInUnerasing y -> Jenc.int y |
| 1883 | - IntegerMapInUnerasing y -> Jenc.dict identity Jenc.int y | |
| 1883 | + IntegerMapInUnerasing y -> makeDictEncoder identity Jenc.int y | |
| 1884 | 1884 | |
| 1885 | 1885 | unguentarium : Jdec.Decoder Unguentarium |
| 1886 | 1886 | unguentarium = |
| @@ -1979,7 +1979,7 @@ encodeUnmortgaged : Unmortgaged -> Jenc.Value | ||
| 1979 | 1979 | encodeUnmortgaged x = case x of |
| 1980 | 1980 | NullInUnmortgaged -> Jenc.null |
| 1981 | 1981 | DoubleInUnmortgaged y -> Jenc.float y |
| 1982 | - IntegerMapInUnmortgaged y -> Jenc.dict identity Jenc.int y | |
| 1982 | + IntegerMapInUnmortgaged y -> makeDictEncoder identity Jenc.int y | |
| 1983 | 1983 | |
| 1984 | 1984 | unobstructed : Jdec.Decoder Unobstructed |
| 1985 | 1985 | unobstructed = |
| @@ -2098,7 +2098,7 @@ encodeUntasked : Untasked -> Jenc.Value | ||
| 2098 | 2098 | encodeUntasked x = case x of |
| 2099 | 2099 | NullArrayInUntasked y -> Jenc.array (always Jenc.null) y |
| 2100 | 2100 | DoubleInUntasked y -> Jenc.float y |
| 2101 | - IntegerMapInUntasked y -> Jenc.dict identity Jenc.int y | |
| 2101 | + IntegerMapInUntasked y -> makeDictEncoder identity Jenc.int y | |
| 2102 | 2102 | |
| 2103 | 2103 | unvarying : Jdec.Decoder Unvarying |
| 2104 | 2104 | unvarying = |
| @@ -2112,7 +2112,7 @@ encodeUnvarying : Unvarying -> Jenc.Value | ||
| 2112 | 2112 | encodeUnvarying x = case x of |
| 2113 | 2113 | BoolInUnvarying y -> Jenc.bool y |
| 2114 | 2114 | DoubleInUnvarying y -> Jenc.float y |
| 2115 | - IntegerMapInUnvarying y -> Jenc.dict identity Jenc.int y | |
| 2115 | + IntegerMapInUnvarying y -> makeDictEncoder identity Jenc.int y | |
| 2116 | 2116 | |
| 2117 | 2117 | vehemently : Jdec.Decoder Vehemently |
| 2118 | 2118 | vehemently = |
| @@ -2203,6 +2203,14 @@ encodeWrothyClass x = | ||
| 2203 | 2203 | |
| 2204 | 2204 | --- encoder helpers |
| 2205 | 2205 | |
| 2206 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 2207 | +makeDictEncoder f m r = | |
| 2208 | + r | |
| 2209 | + |> Dict.toList | |
| 2210 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 2211 | + |> String.join "," | |
| 2212 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 2213 | + | |
| 2206 | 2214 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 2207 | 2215 | makeNullableEncoder f m = |
| 2208 | 2216 | case m of |
Melmdefault / QuickType.elm+19 −11
| @@ -829,7 +829,7 @@ encodeQuickType x = | ||
| 829 | 829 | , ("untasked", Jenc.list encodeUntasked x.untasked) |
| 830 | 830 | , ("unvarying", Jenc.list encodeUnvarying x.unvarying) |
| 831 | 831 | , ("vehemently", Jenc.list encodeVehemently x.vehemently) |
| 832 | - , ("warriorship", Jenc.dict identity Jenc.bool x.warriorship) | |
| 832 | + , ("warriorship", makeDictEncoder identity Jenc.bool x.warriorship) | |
| 833 | 833 | , ("whitepot", Jenc.list encodeWhitepot x.whitepot) |
| 834 | 834 | , ("wrothy", Jenc.list encodeWrothyElement x.wrothy) |
| 835 | 835 | ] |
| @@ -1013,7 +1013,7 @@ querier = | ||
| 1013 | 1013 | encodeQuerier : Querier -> Jenc.Value |
| 1014 | 1014 | encodeQuerier x = case x of |
| 1015 | 1015 | BoolInQuerier y -> Jenc.bool y |
| 1016 | - IntegerMapInQuerier y -> Jenc.dict identity Jenc.int y | |
| 1016 | + IntegerMapInQuerier y -> makeDictEncoder identity Jenc.int y | |
| 1017 | 1017 | |
| 1018 | 1018 | rebarbative : Jdec.Decoder Rebarbative |
| 1019 | 1019 | rebarbative = |
| @@ -1311,7 +1311,7 @@ encodeSaprophilous : Saprophilous -> Jenc.Value | ||
| 1311 | 1311 | encodeSaprophilous x = case x of |
| 1312 | 1312 | NullInSaprophilous -> Jenc.null |
| 1313 | 1313 | StringInSaprophilous y -> Jenc.string y |
| 1314 | - IntegerMapInSaprophilous y -> Jenc.dict identity Jenc.int y | |
| 1314 | + IntegerMapInSaprophilous y -> makeDictEncoder identity Jenc.int y | |
| 1315 | 1315 | |
| 1316 | 1316 | saxtenElement : Jdec.Decoder SaxtenElement |
| 1317 | 1317 | saxtenElement = |
| @@ -1445,7 +1445,7 @@ encodeScoffer : Scoffer -> Jenc.Value | ||
| 1445 | 1445 | encodeScoffer x = case x of |
| 1446 | 1446 | NullArrayInScoffer y -> Jenc.list (always Jenc.null) y |
| 1447 | 1447 | NullInScoffer -> Jenc.null |
| 1448 | - IntegerMapInScoffer y -> Jenc.dict identity Jenc.int y | |
| 1448 | + IntegerMapInScoffer y -> makeDictEncoder identity Jenc.int y | |
| 1449 | 1449 | |
| 1450 | 1450 | scrampum : Jdec.Decoder Scrampum |
| 1451 | 1451 | scrampum = |
| @@ -1631,7 +1631,7 @@ encodeStimulability : Stimulability -> Jenc.Value | ||
| 1631 | 1631 | encodeStimulability x = case x of |
| 1632 | 1632 | BoolInStimulability y -> Jenc.bool y |
| 1633 | 1633 | IntegerInStimulability y -> Jenc.int y |
| 1634 | - IntegerMapInStimulability y -> Jenc.dict identity Jenc.int y | |
| 1634 | + IntegerMapInStimulability y -> makeDictEncoder identity Jenc.int y | |
| 1635 | 1635 | |
| 1636 | 1636 | strangleable : Jdec.Decoder Strangleable |
| 1637 | 1637 | strangleable = |
| @@ -1851,7 +1851,7 @@ encodeUnbeginning : Unbeginning -> Jenc.Value | ||
| 1851 | 1851 | encodeUnbeginning x = case x of |
| 1852 | 1852 | NullArrayInUnbeginning y -> Jenc.list (always Jenc.null) y |
| 1853 | 1853 | StringInUnbeginning y -> Jenc.string y |
| 1854 | - IntegerMapInUnbeginning y -> Jenc.dict identity Jenc.int y | |
| 1854 | + IntegerMapInUnbeginning y -> makeDictEncoder identity Jenc.int y | |
| 1855 | 1855 | |
| 1856 | 1856 | undesirability : Jdec.Decoder Undesirability |
| 1857 | 1857 | undesirability = |
| @@ -1865,7 +1865,7 @@ encodeUndesirability : Undesirability -> Jenc.Value | ||
| 1865 | 1865 | encodeUndesirability x = case x of |
| 1866 | 1866 | IntegerArrayInUndesirability y -> Jenc.list Jenc.int y |
| 1867 | 1867 | StringInUndesirability y -> Jenc.string y |
| 1868 | - IntegerMapInUndesirability y -> Jenc.dict identity Jenc.int y | |
| 1868 | + IntegerMapInUndesirability y -> makeDictEncoder identity Jenc.int y | |
| 1869 | 1869 | |
| 1870 | 1870 | unerasing : Jdec.Decoder Unerasing |
| 1871 | 1871 | unerasing = |
| @@ -1879,7 +1879,7 @@ encodeUnerasing : Unerasing -> Jenc.Value | ||
| 1879 | 1879 | encodeUnerasing x = case x of |
| 1880 | 1880 | NullArrayInUnerasing y -> Jenc.list (always Jenc.null) y |
| 1881 | 1881 | IntegerInUnerasing y -> Jenc.int y |
| 1882 | - IntegerMapInUnerasing y -> Jenc.dict identity Jenc.int y | |
| 1882 | + IntegerMapInUnerasing y -> makeDictEncoder identity Jenc.int y | |
| 1883 | 1883 | |
| 1884 | 1884 | unguentarium : Jdec.Decoder Unguentarium |
| 1885 | 1885 | unguentarium = |
| @@ -1978,7 +1978,7 @@ encodeUnmortgaged : Unmortgaged -> Jenc.Value | ||
| 1978 | 1978 | encodeUnmortgaged x = case x of |
| 1979 | 1979 | NullInUnmortgaged -> Jenc.null |
| 1980 | 1980 | DoubleInUnmortgaged y -> Jenc.float y |
| 1981 | - IntegerMapInUnmortgaged y -> Jenc.dict identity Jenc.int y | |
| 1981 | + IntegerMapInUnmortgaged y -> makeDictEncoder identity Jenc.int y | |
| 1982 | 1982 | |
| 1983 | 1983 | unobstructed : Jdec.Decoder Unobstructed |
| 1984 | 1984 | unobstructed = |
| @@ -2097,7 +2097,7 @@ encodeUntasked : Untasked -> Jenc.Value | ||
| 2097 | 2097 | encodeUntasked x = case x of |
| 2098 | 2098 | NullArrayInUntasked y -> Jenc.list (always Jenc.null) y |
| 2099 | 2099 | DoubleInUntasked y -> Jenc.float y |
| 2100 | - IntegerMapInUntasked y -> Jenc.dict identity Jenc.int y | |
| 2100 | + IntegerMapInUntasked y -> makeDictEncoder identity Jenc.int y | |
| 2101 | 2101 | |
| 2102 | 2102 | unvarying : Jdec.Decoder Unvarying |
| 2103 | 2103 | unvarying = |
| @@ -2111,7 +2111,7 @@ encodeUnvarying : Unvarying -> Jenc.Value | ||
| 2111 | 2111 | encodeUnvarying x = case x of |
| 2112 | 2112 | BoolInUnvarying y -> Jenc.bool y |
| 2113 | 2113 | DoubleInUnvarying y -> Jenc.float y |
| 2114 | - IntegerMapInUnvarying y -> Jenc.dict identity Jenc.int y | |
| 2114 | + IntegerMapInUnvarying y -> makeDictEncoder identity Jenc.int y | |
| 2115 | 2115 | |
| 2116 | 2116 | vehemently : Jdec.Decoder Vehemently |
| 2117 | 2117 | vehemently = |
| @@ -2202,6 +2202,14 @@ encodeWrothyClass x = | ||
| 2202 | 2202 | |
| 2203 | 2203 | --- encoder helpers |
| 2204 | 2204 | |
| 2205 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 2206 | +makeDictEncoder f m r = | |
| 2207 | + r | |
| 2208 | + |> Dict.toList | |
| 2209 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 2210 | + |> String.join "," | |
| 2211 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 2212 | + | |
| 2205 | 2213 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 2206 | 2214 | makeNullableEncoder f m = |
| 2207 | 2215 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mflownice-property-names-true--f4d7920ee2ce / TopLevel.js+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mflowprefer-unions-false--a5053c0a486d / TopLevel.js+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mflowprefer-unknown-false--f1ab9e45d823 / TopLevel.js+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mflowruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = val[key]; |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mjavascriptconverters-top-level--67aa452ed509 / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptraw-type-any--474b307c39db / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = val[key]; |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptacronym-style-pascal--d9e0c1bd777a / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptconverters-all-objects--3a443babd1cb / TopLevel.ts+2 −2
| @@ -753,7 +753,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 753 | 753 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 754 | 754 | return invalidValue(l(ref || "object"), val, key, parent); |
| 755 | 755 | } |
| 756 | - const result: any = {}; | |
| 756 | + const result: any = Object.create(null); | |
| 757 | 757 | Object.getOwnPropertyNames(props).forEach(key => { |
| 758 | 758 | const prop = props[key]; |
| 759 | 759 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -764,7 +764,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 764 | 764 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 765 | 765 | } |
| 766 | 766 | }); |
| 767 | - return result; | |
| 767 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptnice-property-names-true--f4d7920ee2ce / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptprefer-const-values-true--6b26e4d1265c / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptprefer-types-true--df33e18681f9 / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptprefer-unions-false--a5053c0a486d / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptprefer-unknown-false--f1ab9e45d823 / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptraw-type-any--474b307c39db / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptreadonly-true--24da4fc107df / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Mtypescriptruntime-typecheck-ignore-unknown-properties-true--d792c40f022e / TopLevel.ts+2 −2
| @@ -625,7 +625,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 625 | 625 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 626 | 626 | return invalidValue(l(ref || "object"), val, key, parent); |
| 627 | 627 | } |
| 628 | - const result: any = {}; | |
| 628 | + const result: any = Object.create(null); | |
| 629 | 629 | Object.getOwnPropertyNames(props).forEach(key => { |
| 630 | 630 | const prop = props[key]; |
| 631 | 631 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -636,7 +636,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 636 | 636 | result[key] = val[key]; |
| 637 | 637 | } |
| 638 | 638 | }); |
| 639 | - return result; | |
| 639 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/combined-enum.json
Melmdefault / QuickType.elm+8 −0
| @@ -92,6 +92,14 @@ encodeX x = case x of | ||
| 92 | 92 | |
| 93 | 93 | --- encoder helpers |
| 94 | 94 | |
| 95 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 96 | +makeDictEncoder f m r = | |
| 97 | + r | |
| 98 | + |> Dict.toList | |
| 99 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 100 | + |> String.join "," | |
| 101 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 102 | + | |
| 95 | 103 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 96 | 104 | makeNullableEncoder f m = |
| 97 | 105 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/json/priority/direct-recursive.json
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/empty-enum.json
Melmdefault / QuickType.elm+8 −0
| @@ -66,6 +66,14 @@ encodeFoo x = | ||
| 66 | 66 | |
| 67 | 67 | --- encoder helpers |
| 68 | 68 | |
| 69 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 70 | +makeDictEncoder f m r = | |
| 71 | + r | |
| 72 | + |> Dict.toList | |
| 73 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 74 | + |> String.join "," | |
| 75 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 76 | + | |
| 69 | 77 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 70 | 78 | makeNullableEncoder f m = |
| 71 | 79 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/identifiers.json
Melmdefault / QuickType.elm+8 −0
| @@ -169,6 +169,14 @@ encodeThisIsAToughOne x = | ||
| 169 | 169 | |
| 170 | 170 | --- encoder helpers |
| 171 | 171 | |
| 172 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 173 | +makeDictEncoder f m r = | |
| 174 | + r | |
| 175 | + |> Dict.toList | |
| 176 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 177 | + |> String.join "," | |
| 178 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 179 | + | |
| 172 | 180 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 173 | 181 | makeNullableEncoder f m = |
| 174 | 182 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 139 | 139 | return invalidValue(l(ref || "object"), val, key, parent); |
| 140 | 140 | } |
| 141 | - const result: any = {}; | |
| 141 | + const result: any = Object.create(null); | |
| 142 | 142 | Object.getOwnPropertyNames(props).forEach(key => { |
| 143 | 143 | const prop = props[key]; |
| 144 | 144 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -149,7 +149,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 149 | 149 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 150 | 150 | } |
| 151 | 151 | }); |
| 152 | - return result; | |
| 152 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 136 | 136 | return invalidValue(l(ref || "object"), val, key, parent); |
| 137 | 137 | } |
| 138 | - const result: any = {}; | |
| 138 | + const result: any = Object.create(null); | |
| 139 | 139 | Object.getOwnPropertyNames(props).forEach(key => { |
| 140 | 140 | const prop = props[key]; |
| 141 | 141 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 147 | 147 | } |
| 148 | 148 | }); |
| 149 | - return result; | |
| 149 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/issue2680-object-array.json
Melmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickTypeElement x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/issue2680-scalar-array.json
Melmdefault / QuickType.elm+8 −0
| @@ -40,6 +40,14 @@ quickTypeToString r = Jenc.encode 0 (Jenc.list Jenc.int r) | ||
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
5 generated files · +16 −8test/inputs/json/priority/keywords.json
Melmdefault / QuickType.elm+8 −0
| @@ -6606,6 +6606,14 @@ encodeYield x = | ||
| 6606 | 6606 | |
| 6607 | 6607 | --- encoder helpers |
| 6608 | 6608 | |
| 6609 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 6610 | +makeDictEncoder f m r = | |
| 6611 | + r | |
| 6612 | + |> Dict.toList | |
| 6613 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 6614 | + |> String.join "," | |
| 6615 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 6616 | + | |
| 6609 | 6617 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 6610 | 6618 | makeNullableEncoder f m = |
| 6611 | 6619 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -1831,7 +1831,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1831 | 1831 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 1832 | 1832 | return invalidValue(l(ref || "object"), val, key, parent); |
| 1833 | 1833 | } |
| 1834 | - const result: any = {}; | |
| 1834 | + const result: any = Object.create(null); | |
| 1835 | 1835 | Object.getOwnPropertyNames(props).forEach(key => { |
| 1836 | 1836 | const prop = props[key]; |
| 1837 | 1837 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -1842,7 +1842,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1842 | 1842 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 1843 | 1843 | } |
| 1844 | 1844 | }); |
| 1845 | - return result; | |
| 1845 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | 1848 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -1829,7 +1829,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1829 | 1829 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 1830 | 1830 | return invalidValue(l(ref || "object"), val, key, parent); |
| 1831 | 1831 | } |
| 1832 | - const result: any = {}; | |
| 1832 | + const result: any = Object.create(null); | |
| 1833 | 1833 | Object.getOwnPropertyNames(props).forEach(key => { |
| 1834 | 1834 | const prop = props[key]; |
| 1835 | 1835 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -1840,7 +1840,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1840 | 1840 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 1841 | 1841 | } |
| 1842 | 1842 | }); |
| 1843 | - return result; | |
| 1843 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | if (typ === "any") return val; |
Mtypescriptprefer-types-true--df33e18681f9 / TopLevel.ts+2 −2
| @@ -1829,7 +1829,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1829 | 1829 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 1830 | 1830 | return invalidValue(l(ref || "object"), val, key, parent); |
| 1831 | 1831 | } |
| 1832 | - const result: any = {}; | |
| 1832 | + const result: any = Object.create(null); | |
| 1833 | 1833 | Object.getOwnPropertyNames(props).forEach(key => { |
| 1834 | 1834 | const prop = props[key]; |
| 1835 | 1835 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -1840,7 +1840,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1840 | 1840 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 1841 | 1841 | } |
| 1842 | 1842 | }); |
| 1843 | - return result; | |
| 1843 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/kotlin-enum-class-case-collision.json
Melmdefault / QuickType.elm+8 −0
| @@ -76,6 +76,14 @@ encodeCategoryEnum x = case x of | ||
| 76 | 76 | |
| 77 | 77 | --- encoder helpers |
| 78 | 78 | |
| 79 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 80 | +makeDictEncoder f m r = | |
| 81 | + r | |
| 82 | + |> Dict.toList | |
| 83 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 84 | + |> String.join "," | |
| 85 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 86 | + | |
| 79 | 87 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 80 | 88 | makeNullableEncoder f m = |
| 81 | 89 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/json/priority/list.json
Mflowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/name-style.json
Melmdefault / QuickType.elm+8 −0
| @@ -68,6 +68,14 @@ encodeQuickType x = | ||
| 68 | 68 | |
| 69 | 69 | --- encoder helpers |
| 70 | 70 | |
| 71 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 72 | +makeDictEncoder f m r = | |
| 73 | + r | |
| 74 | + |> Dict.toList | |
| 75 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 76 | + |> String.join "," | |
| 77 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 78 | + | |
| 71 | 79 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 72 | 80 | makeNullableEncoder f m = |
| 73 | 81 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +26 −18test/inputs/json/priority/nbl-stats.json
Melmdefault / QuickType.elm+20 −12
| @@ -436,9 +436,9 @@ encodeQuickType x = | ||
| 436 | 436 | , ("periodLengthREGULAR", Jenc.int x.periodLengthREGULAR) |
| 437 | 437 | , ("periodType", encodePerType x.periodType) |
| 438 | 438 | , ("periodsMax", Jenc.int x.periodsMax) |
| 439 | - , ("scorers", Jenc.dict identity (Jenc.list encodeScorer) x.scorers) | |
| 439 | + , ("scorers", makeDictEncoder identity (Jenc.list encodeScorer) x.scorers) | |
| 440 | 440 | , ("timeline", Jenc.list identity x.timeline) |
| 441 | - , ("tm", Jenc.dict identity encodeTm x.tm) | |
| 441 | + , ("tm", makeDictEncoder identity encodeTm x.tm) | |
| 442 | 442 | , ("totalTimeAdded", Jenc.int x.totalTimeAdded) |
| 443 | 443 | , ("totallds", encodeTotallds x.totallds) |
| 444 | 444 | ] |
| @@ -878,7 +878,7 @@ encodeTm x = | ||
| 878 | 878 | , ("p2_score", Jenc.int x.p2Score) |
| 879 | 879 | , ("p3_score", Jenc.int x.p3Score) |
| 880 | 880 | , ("p4_score", Jenc.int x.p4Score) |
| 881 | - , ("pl", Jenc.dict identity encodePl x.pl) | |
| 881 | + , ("pl", makeDictEncoder identity encodePl x.pl) | |
| 882 | 882 | , ("score", Jenc.int x.score) |
| 883 | 883 | , ("scoring", Jenc.list encodeScorer x.scoring) |
| 884 | 884 | , ("shortName", Jenc.string x.shortName) |
| @@ -945,11 +945,11 @@ lds = | ||
| 945 | 945 | encodeLds : Lds -> Jenc.Value |
| 946 | 946 | encodeLds x = |
| 947 | 947 | Jenc.object |
| 948 | - [ ("sAssists", Jenc.dict identity encodeScorer x.sAssists) | |
| 948 | + [ ("sAssists", makeDictEncoder identity encodeScorer x.sAssists) | |
| 949 | 949 | , ("sBlocks", encodeSBlocks x.sBlocks) |
| 950 | - , ("sPoints", Jenc.dict identity encodeScorer x.sPoints) | |
| 951 | - , ("sReboundsTotal", Jenc.dict identity encodeScorer x.sReboundsTotal) | |
| 952 | - , ("sSteals", Jenc.dict identity encodeScorer x.sSteals) | |
| 950 | + , ("sPoints", makeDictEncoder identity encodeScorer x.sPoints) | |
| 951 | + , ("sReboundsTotal", makeDictEncoder identity encodeScorer x.sReboundsTotal) | |
| 952 | + , ("sSteals", makeDictEncoder identity encodeScorer x.sSteals) | |
| 953 | 953 | ] |
| 954 | 954 | |
| 955 | 955 | sBlocks : Jdec.Decoder SBlocks |
| @@ -1163,15 +1163,23 @@ totallds = | ||
| 1163 | 1163 | encodeTotallds : Totallds -> Jenc.Value |
| 1164 | 1164 | encodeTotallds x = |
| 1165 | 1165 | Jenc.object |
| 1166 | - [ ("sAssists", Jenc.dict identity encodeScorer x.sAssists) | |
| 1167 | - , ("sBlocks", Jenc.dict identity encodeScorer x.sBlocks) | |
| 1168 | - , ("sPoints", Jenc.dict identity encodeScorer x.sPoints) | |
| 1169 | - , ("sReboundsTotal", Jenc.dict identity encodeScorer x.sReboundsTotal) | |
| 1170 | - , ("sSteals", Jenc.dict identity encodeScorer x.sSteals) | |
| 1166 | + [ ("sAssists", makeDictEncoder identity encodeScorer x.sAssists) | |
| 1167 | + , ("sBlocks", makeDictEncoder identity encodeScorer x.sBlocks) | |
| 1168 | + , ("sPoints", makeDictEncoder identity encodeScorer x.sPoints) | |
| 1169 | + , ("sReboundsTotal", makeDictEncoder identity encodeScorer x.sReboundsTotal) | |
| 1170 | + , ("sSteals", makeDictEncoder identity encodeScorer x.sSteals) | |
| 1171 | 1171 | ] |
| 1172 | 1172 | |
| 1173 | 1173 | --- encoder helpers |
| 1174 | 1174 | |
| 1175 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1176 | +makeDictEncoder f m r = | |
| 1177 | + r | |
| 1178 | + |> Dict.toList | |
| 1179 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1180 | + |> String.join "," | |
| 1181 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1182 | + | |
| 1175 | 1183 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1176 | 1184 | makeNullableEncoder f m = |
| 1177 | 1185 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -439,7 +439,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 439 | 439 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 440 | 440 | return invalidValue(l(ref || "object"), val, key, parent); |
| 441 | 441 | } |
| 442 | - const result: any = {}; | |
| 442 | + const result: any = Object.create(null); | |
| 443 | 443 | Object.getOwnPropertyNames(props).forEach(key => { |
| 444 | 444 | const prop = props[key]; |
| 445 | 445 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -450,7 +450,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 450 | 450 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 451 | 451 | } |
| 452 | 452 | }); |
| 453 | - return result; | |
| 453 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -384,7 +384,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 384 | 384 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 385 | 385 | return invalidValue(l(ref || "object"), val, key, parent); |
| 386 | 386 | } |
| 387 | - const result: any = {}; | |
| 387 | + const result: any = Object.create(null); | |
| 388 | 388 | Object.getOwnPropertyNames(props).forEach(key => { |
| 389 | 389 | const prop = props[key]; |
| 390 | 390 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -395,7 +395,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 395 | 395 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 396 | 396 | } |
| 397 | 397 | }); |
| 398 | - return result; | |
| 398 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | if (typ === "any") return val; |
Test case
5 generated files · +18 −10test/inputs/json/priority/nested-objects.json
Melmdefault / QuickType.elm+10 −2
| @@ -47,12 +47,20 @@ quickType = | ||
| 47 | 47 | encodeQuickType : QuickType -> Jenc.Value |
| 48 | 48 | encodeQuickType x = |
| 49 | 49 | Jenc.object |
| 50 | - [ ("a", Jenc.dict identity Jenc.int x.a) | |
| 51 | - , ("b", Jenc.dict identity Jenc.int x.b) | |
| 50 | + [ ("a", makeDictEncoder identity Jenc.int x.a) | |
| 51 | + , ("b", makeDictEncoder identity Jenc.int x.b) | |
| 52 | 52 | ] |
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mjavascriptconverters-all-objects--3a443babd1cb / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/no-classes.json
Melmdefault / QuickType.elm+8 −0
| @@ -40,6 +40,14 @@ quickTypeToString r = Jenc.encode 0 (Jenc.int r) | ||
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/nst-test-suite.json
Melmdefault / QuickType.elm+8 −0
| @@ -533,6 +533,14 @@ encodeYObjectWithNewlinesJSON x = | ||
| 533 | 533 | |
| 534 | 534 | --- encoder helpers |
| 535 | 535 | |
| 536 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 537 | +makeDictEncoder f m r = | |
| 538 | + r | |
| 539 | + |> Dict.toList | |
| 540 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 541 | + |> String.join "," | |
| 542 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 543 | + | |
| 536 | 544 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 537 | 545 | makeNullableEncoder f m = |
| 538 | 546 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -247,7 +247,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 247 | 247 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 248 | 248 | return invalidValue(l(ref || "object"), val, key, parent); |
| 249 | 249 | } |
| 250 | - const result: any = {}; | |
| 250 | + const result: any = Object.create(null); | |
| 251 | 251 | Object.getOwnPropertyNames(props).forEach(key => { |
| 252 | 252 | const prop = props[key]; |
| 253 | 253 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -258,7 +258,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 258 | 258 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 259 | 259 | } |
| 260 | 260 | }); |
| 261 | - return result; | |
| 261 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -244,7 +244,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 244 | 244 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 245 | 245 | return invalidValue(l(ref || "object"), val, key, parent); |
| 246 | 246 | } |
| 247 | - const result: any = {}; | |
| 247 | + const result: any = Object.create(null); | |
| 248 | 248 | Object.getOwnPropertyNames(props).forEach(key => { |
| 249 | 249 | const prop = props[key]; |
| 250 | 250 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -255,7 +255,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 255 | 255 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 256 | 256 | } |
| 257 | 257 | }); |
| 258 | - return result; | |
| 258 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/priority/number-map.json
Melmdefault / QuickType.elm+9 −1
| @@ -45,11 +45,19 @@ quickType = | ||
| 45 | 45 | encodeQuickType : QuickType -> Jenc.Value |
| 46 | 46 | encodeQuickType x = |
| 47 | 47 | Jenc.object |
| 48 | - [ ("foo", Jenc.dict identity Jenc.float x.foo) | |
| 48 | + [ ("foo", makeDictEncoder identity Jenc.float x.foo) | |
| 49 | 49 | ] |
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/omit-empty.json
Melmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeResult x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/optional-union.json
Melmdefault / QuickType.elm+8 −0
| @@ -73,6 +73,14 @@ encodeA x = case x of | ||
| 73 | 73 | |
| 74 | 74 | --- encoder helpers |
| 75 | 75 | |
| 76 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 77 | +makeDictEncoder f m r = | |
| 78 | + r | |
| 79 | + |> Dict.toList | |
| 80 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 81 | + |> String.join "," | |
| 82 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 83 | + | |
| 76 | 84 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 77 | 85 | makeNullableEncoder f m = |
| 78 | 86 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/php-mixed-union.json
Melmdefault / QuickType.elm+8 −0
| @@ -92,6 +92,14 @@ encodeMixedClass x = | ||
| 92 | 92 | |
| 93 | 93 | --- encoder helpers |
| 94 | 94 | |
| 95 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 96 | +makeDictEncoder f m r = | |
| 97 | + r | |
| 98 | + |> Dict.toList | |
| 99 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 100 | + |> String.join "," | |
| 101 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 102 | + | |
| 95 | 103 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 96 | 104 | makeNullableEncoder f m = |
| 97 | 105 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/php-validation.json
Melmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickType x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/json/priority/recursive.json
Mflowdefault / TopLevel.js+2 −2
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 227 | 227 | return invalidValue(l(ref || "object"), val, key, parent); |
| 228 | 228 | } |
| 229 | - const result: any = {}; | |
| 229 | + const result: any = Object.create(null); | |
| 230 | 230 | Object.getOwnPropertyNames(props).forEach(key => { |
| 231 | 231 | const prop = props[key]; |
| 232 | 232 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -237,7 +237,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 237 | 237 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 238 | 238 | } |
| 239 | 239 | }); |
| 240 | - return result; | |
| 240 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -226,7 +226,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 226 | 226 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 227 | 227 | return invalidValue(l(ref || "object"), val, key, parent); |
| 228 | 228 | } |
| 229 | - const result: any = {}; | |
| 229 | + const result: any = Object.create(null); | |
| 230 | 230 | Object.getOwnPropertyNames(props).forEach(key => { |
| 231 | 231 | const prop = props[key]; |
| 232 | 232 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -237,7 +237,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 237 | 237 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 238 | 238 | } |
| 239 | 239 | }); |
| 240 | - return result; | |
| 240 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/simple-identifiers.json
Melmdefault / QuickType.elm+8 −0
| @@ -74,6 +74,14 @@ encodeQuickType x = | ||
| 74 | 74 | |
| 75 | 75 | --- encoder helpers |
| 76 | 76 | |
| 77 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 78 | +makeDictEncoder f m r = | |
| 79 | + r | |
| 80 | + |> Dict.toList | |
| 81 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 82 | + |> String.join "," | |
| 83 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 84 | + | |
| 77 | 85 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 78 | 86 | makeNullableEncoder f m = |
| 79 | 87 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/union-constructor-clash.json
Melmdefault / QuickType.elm+8 −0
| @@ -86,6 +86,14 @@ encodeUnion x = case x of | ||
| 86 | 86 | |
| 87 | 87 | --- encoder helpers |
| 88 | 88 | |
| 89 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 90 | +makeDictEncoder f m r = | |
| 91 | + r | |
| 92 | + |> Dict.toList | |
| 93 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 94 | + |> String.join "," | |
| 95 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 96 | + | |
| 89 | 97 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 90 | 98 | makeNullableEncoder f m = |
| 91 | 99 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/unions.json
Melmdefault / QuickType.elm+8 −0
| @@ -112,6 +112,14 @@ encodeZClass x = | ||
| 112 | 112 | |
| 113 | 113 | --- encoder helpers |
| 114 | 114 | |
| 115 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 116 | +makeDictEncoder f m r = | |
| 117 | + r | |
| 118 | + |> Dict.toList | |
| 119 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 120 | + |> String.join "," | |
| 121 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 122 | + | |
| 115 | 123 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 116 | 124 | makeNullableEncoder f m = |
| 117 | 125 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/url.json
Melmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/priority/uuids.json
Melmdefault / QuickType.elm+8 −0
| @@ -65,6 +65,14 @@ encodeQuickType x = | ||
| 65 | 65 | |
| 66 | 66 | --- encoder helpers |
| 67 | 67 | |
| 68 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 69 | +makeDictEncoder f m r = | |
| 70 | + r | |
| 71 | + |> Dict.toList | |
| 72 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 73 | + |> String.join "," | |
| 74 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 75 | + | |
| 68 | 76 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 69 | 77 | makeNullableEncoder f m = |
| 70 | 78 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/bitcoin-block.json
Melmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickType x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/copy-with-property.json
Melmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/getting-started.json
Melmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/github-events.json
Melmdefault / QuickType.elm+8 −0
| @@ -986,6 +986,14 @@ encodeQuickTypeRepo x = | ||
| 986 | 986 | |
| 987 | 987 | --- encoder helpers |
| 988 | 988 | |
| 989 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 990 | +makeDictEncoder f m r = | |
| 991 | + r | |
| 992 | + |> Dict.toList | |
| 993 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 994 | + |> String.join "," | |
| 995 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 996 | + | |
| 989 | 997 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 990 | 998 | makeNullableEncoder f m = |
| 991 | 999 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -395,7 +395,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 395 | 395 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 396 | 396 | return invalidValue(l(ref || "object"), val, key, parent); |
| 397 | 397 | } |
| 398 | - const result: any = {}; | |
| 398 | + const result: any = Object.create(null); | |
| 399 | 399 | Object.getOwnPropertyNames(props).forEach(key => { |
| 400 | 400 | const prop = props[key]; |
| 401 | 401 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -406,7 +406,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 406 | 406 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 407 | 407 | } |
| 408 | 408 | }); |
| 409 | - return result; | |
| 409 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -393,7 +393,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 393 | 393 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 394 | 394 | return invalidValue(l(ref || "object"), val, key, parent); |
| 395 | 395 | } |
| 396 | - const result: any = {}; | |
| 396 | + const result: any = Object.create(null); | |
| 397 | 397 | Object.getOwnPropertyNames(props).forEach(key => { |
| 398 | 398 | const prop = props[key]; |
| 399 | 399 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -404,7 +404,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 404 | 404 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 405 | 405 | } |
| 406 | 406 | }); |
| 407 | - return result; | |
| 407 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | if (typ === "any") return val; |
Test case
4 generated files · +16 −8test/inputs/json/samples/kitchen-sink.json
Melmdefault / QuickType.elm+10 −2
| @@ -105,10 +105,10 @@ encodeQuickType x = | ||
| 105 | 105 | , ("differentThings", Jenc.list encodeDifferentThingElement x.differentThings) |
| 106 | 106 | , ("doubleValue", Jenc.float x.doubleValue) |
| 107 | 107 | , ("intValue", Jenc.int x.intValue) |
| 108 | - , ("mapValue", Jenc.dict identity (makeNullableEncoder Jenc.int) x.mapValue) | |
| 108 | + , ("mapValue", makeDictEncoder identity (makeNullableEncoder Jenc.int) x.mapValue) | |
| 109 | 109 | , ("name with spaces", always Jenc.null x.nameWithSpaces) |
| 110 | 110 | , ("nullValue", always Jenc.null x.nullValue) |
| 111 | - , ("nullableMapValue", Jenc.dict identity (makeNullableEncoder Jenc.int) x.nullableMapValue) | |
| 111 | + , ("nullableMapValue", makeDictEncoder identity (makeNullableEncoder Jenc.int) x.nullableMapValue) | |
| 112 | 112 | , ("people", Jenc.list encodePersonElement x.people) |
| 113 | 113 | , ("person", encodePurplePerson x.person) |
| 114 | 114 | , ("stringValue", Jenc.string x.stringValue) |
| @@ -183,6 +183,14 @@ encodePurplePerson x = | ||
| 183 | 183 | |
| 184 | 184 | --- encoder helpers |
| 185 | 185 | |
| 186 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 187 | +makeDictEncoder f m r = | |
| 188 | + r | |
| 189 | + |> Dict.toList | |
| 190 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 191 | + |> String.join "," | |
| 192 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 193 | + | |
| 186 | 194 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 187 | 195 | makeNullableEncoder f m = |
| 188 | 196 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 140 | 140 | return invalidValue(l(ref || "object"), val, key, parent); |
| 141 | 141 | } |
| 142 | - const result: any = {}; | |
| 142 | + const result: any = Object.create(null); | |
| 143 | 143 | Object.getOwnPropertyNames(props).forEach(key => { |
| 144 | 144 | const prop = props[key]; |
| 145 | 145 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -150,7 +150,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 150 | 150 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 151 | 151 | } |
| 152 | 152 | }); |
| 153 | - return result; | |
| 153 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 140 | 140 | return invalidValue(l(ref || "object"), val, key, parent); |
| 141 | 141 | } |
| 142 | - const result: any = {}; | |
| 142 | + const result: any = Object.create(null); | |
| 143 | 143 | Object.getOwnPropertyNames(props).forEach(key => { |
| 144 | 144 | const prop = props[key]; |
| 145 | 145 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -150,7 +150,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 150 | 150 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 151 | 151 | } |
| 152 | 152 | }); |
| 153 | - return result; | |
| 153 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/null-safe.json
Melmdefault / QuickType.elm+8 −0
| @@ -97,6 +97,14 @@ encodeAddress x = | ||
| 97 | 97 | |
| 98 | 98 | --- encoder helpers |
| 99 | 99 | |
| 100 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 101 | +makeDictEncoder f m r = | |
| 102 | + r | |
| 103 | + |> Dict.toList | |
| 104 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 105 | + |> String.join "," | |
| 106 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 107 | + | |
| 100 | 108 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 101 | 109 | makeNullableEncoder f m = |
| 102 | 110 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/objc-control-characters.json
Melmdefault / QuickType.elm+8 −0
| @@ -76,6 +76,14 @@ encodeValue x = case x of | ||
| 76 | 76 | |
| 77 | 77 | --- encoder helpers |
| 78 | 78 | |
| 79 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 80 | +makeDictEncoder f m r = | |
| 81 | + r | |
| 82 | + |> Dict.toList | |
| 83 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 84 | + |> String.join "," | |
| 85 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 86 | + | |
| 79 | 87 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 80 | 88 | makeNullableEncoder f m = |
| 81 | 89 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
5 generated files · +16 −8test/inputs/json/samples/pokedex.json
Melmdefault / QuickType.elm+8 −0
| @@ -230,6 +230,14 @@ encodeType x = case x of | ||
| 230 | 230 | |
| 231 | 231 | --- encoder helpers |
| 232 | 232 | |
| 233 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 234 | +makeDictEncoder f m r = | |
| 235 | + r | |
| 236 | + |> Dict.toList | |
| 237 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 238 | + |> String.join "," | |
| 239 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 240 | + | |
| 233 | 241 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 234 | 242 | makeNullableEncoder f m = |
| 235 | 243 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -159,7 +159,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 159 | 159 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 160 | 160 | return invalidValue(l(ref || "object"), val, key, parent); |
| 161 | 161 | } |
| 162 | - const result: any = {}; | |
| 162 | + const result: any = Object.create(null); | |
| 163 | 163 | Object.getOwnPropertyNames(props).forEach(key => { |
| 164 | 164 | const prop = props[key]; |
| 165 | 165 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -170,7 +170,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 170 | 170 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 171 | 171 | } |
| 172 | 172 | }); |
| 173 | - return result; | |
| 173 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Mtypescriptprefer-types-true--df33e18681f9 / TopLevel.ts+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/reddit.json
Melmdefault / QuickType.elm+8 −0
| @@ -575,6 +575,14 @@ encodeKind x = case x of | ||
| 575 | 575 | |
| 576 | 576 | --- encoder helpers |
| 577 | 577 | |
| 578 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 579 | +makeDictEncoder f m r = | |
| 580 | + r | |
| 581 | + |> Dict.toList | |
| 582 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 583 | + |> String.join "," | |
| 584 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 585 | + | |
| 578 | 586 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 579 | 587 | makeNullableEncoder f m = |
| 580 | 588 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -248,7 +248,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 248 | 248 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 249 | 249 | return invalidValue(l(ref || "object"), val, key, parent); |
| 250 | 250 | } |
| 251 | - const result: any = {}; | |
| 251 | + const result: any = Object.create(null); | |
| 252 | 252 | Object.getOwnPropertyNames(props).forEach(key => { |
| 253 | 253 | const prop = props[key]; |
| 254 | 254 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -259,7 +259,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 259 | 259 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 260 | 260 | } |
| 261 | 261 | }); |
| 262 | - return result; | |
| 262 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -233,7 +233,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 233 | 233 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 234 | 234 | return invalidValue(l(ref || "object"), val, key, parent); |
| 235 | 235 | } |
| 236 | - const result: any = {}; | |
| 236 | + const result: any = Object.create(null); | |
| 237 | 237 | Object.getOwnPropertyNames(props).forEach(key => { |
| 238 | 238 | const prop = props[key]; |
| 239 | 239 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -244,7 +244,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 244 | 244 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 245 | 245 | } |
| 246 | 246 | }); |
| 247 | - return result; | |
| 247 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/simple-object.json
Melmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickType x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/spotify-album.json
Melmdefault / QuickType.elm+8 −0
| @@ -288,6 +288,14 @@ encodeItem x = | ||
| 288 | 288 | |
| 289 | 289 | --- encoder helpers |
| 290 | 290 | |
| 291 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 292 | +makeDictEncoder f m r = | |
| 293 | + r | |
| 294 | + |> Dict.toList | |
| 295 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 296 | + |> String.join "," | |
| 297 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 298 | + | |
| 291 | 299 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 292 | 300 | makeNullableEncoder f m = |
| 293 | 301 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -177,7 +177,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 177 | 177 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 178 | 178 | return invalidValue(l(ref || "object"), val, key, parent); |
| 179 | 179 | } |
| 180 | - const result: any = {}; | |
| 180 | + const result: any = Object.create(null); | |
| 181 | 181 | Object.getOwnPropertyNames(props).forEach(key => { |
| 182 | 182 | const prop = props[key]; |
| 183 | 183 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -188,7 +188,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 188 | 188 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 189 | 189 | } |
| 190 | 190 | }); |
| 191 | - return result; | |
| 191 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -177,7 +177,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 177 | 177 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 178 | 178 | return invalidValue(l(ref || "object"), val, key, parent); |
| 179 | 179 | } |
| 180 | - const result: any = {}; | |
| 180 | + const result: any = Object.create(null); | |
| 181 | 181 | Object.getOwnPropertyNames(props).forEach(key => { |
| 182 | 182 | const prop = props[key]; |
| 183 | 183 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -188,7 +188,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 188 | 188 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 189 | 189 | } |
| 190 | 190 | }); |
| 191 | - return result; | |
| 191 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/json/samples/us-avg-temperatures.json
Melmdefault / QuickType.elm+9 −1
| @@ -61,7 +61,7 @@ quickType = | ||
| 61 | 61 | encodeQuickType : QuickType -> Jenc.Value |
| 62 | 62 | encodeQuickType x = |
| 63 | 63 | Jenc.object |
| 64 | - [ ("data", Jenc.dict identity encodeDatum x.data) | |
| 64 | + [ ("data", makeDictEncoder identity encodeDatum x.data) | |
| 65 | 65 | , ("description", encodeDescription x.description) |
| 66 | 66 | ] |
| 67 | 67 | |
| @@ -97,6 +97,14 @@ encodeDescription x = | ||
| 97 | 97 | |
| 98 | 98 | --- encoder helpers |
| 99 | 99 | |
| 100 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 101 | +makeDictEncoder f m r = | |
| 102 | + r | |
| 103 | + |> Dict.toList | |
| 104 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 105 | + |> String.join "," | |
| 106 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 107 | + | |
| 100 | 108 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 101 | 109 | makeNullableEncoder f m = |
| 102 | 110 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/json/samples/us-senators.json
Melmdefault / QuickType.elm+8 −0
| @@ -469,6 +469,14 @@ encodeTitle x = case x of | ||
| 469 | 469 | |
| 470 | 470 | --- encoder helpers |
| 471 | 471 | |
| 472 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 473 | +makeDictEncoder f m r = | |
| 474 | + r | |
| 475 | + |> Dict.toList | |
| 476 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 477 | + |> String.join "," | |
| 478 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 479 | + | |
| 472 | 480 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 473 | 481 | makeNullableEncoder f m = |
| 474 | 482 | case m of |
Mflowdefault / TopLevel.js+2 −2
| @@ -212,7 +212,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 212 | 212 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 213 | 213 | return invalidValue(l(ref || "object"), val, key, parent); |
| 214 | 214 | } |
| 215 | - const result: any = {}; | |
| 215 | + const result: any = Object.create(null); | |
| 216 | 216 | Object.getOwnPropertyNames(props).forEach(key => { |
| 217 | 217 | const prop = props[key]; |
| 218 | 218 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -223,7 +223,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 223 | 223 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 224 | 224 | } |
| 225 | 225 | }); |
| 226 | - return result; | |
| 226 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | if (typ === "any") return val; |
Mjavascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mtypescriptdefault / TopLevel.ts+2 −2
| @@ -189,7 +189,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 189 | 189 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 190 | 190 | return invalidValue(l(ref || "object"), val, key, parent); |
| 191 | 191 | } |
| 192 | - const result: any = {}; | |
| 192 | + const result: any = Object.create(null); | |
| 193 | 193 | Object.getOwnPropertyNames(props).forEach(key => { |
| 194 | 194 | const prop = props[key]; |
| 195 | 195 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -200,7 +200,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 200 | 200 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 201 | 201 | } |
| 202 | 202 | }); |
| 203 | - return result; | |
| 203 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/accessors.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -99,6 +99,14 @@ encodeUnion x = case x of | ||
| 99 | 99 | |
| 100 | 100 | --- encoder helpers |
| 101 | 101 | |
| 102 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 103 | +makeDictEncoder f m r = | |
| 104 | + r | |
| 105 | + |> Dict.toList | |
| 106 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 107 | + |> String.join "," | |
| 108 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 109 | + | |
| 102 | 110 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 103 | 111 | makeNullableEncoder f m = |
| 104 | 112 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/all-of-additional-properties-false.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -102,6 +102,14 @@ encodeType x = case x of | ||
| 102 | 102 | |
| 103 | 103 | --- encoder helpers |
| 104 | 104 | |
| 105 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 106 | +makeDictEncoder f m r = | |
| 107 | + r | |
| 108 | + |> Dict.toList | |
| 109 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 110 | + |> String.join "," | |
| 111 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 112 | + | |
| 105 | 113 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 106 | 114 | makeNullableEncoder f m = |
| 107 | 115 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/schema/any.schema
Mschema-elmdefault / QuickType.elm+9 −1
| @@ -48,11 +48,19 @@ encodeQuickType : QuickType -> Jenc.Value | ||
| 48 | 48 | encodeQuickType x = |
| 49 | 49 | Jenc.object |
| 50 | 50 | [ ("foo", identity x.foo) |
| 51 | - , ("values", Jenc.dict identity identity x.values) | |
| 51 | + , ("values", makeDictEncoder identity identity x.values) | |
| 52 | 52 | ] |
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/bool-string.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -85,6 +85,14 @@ encodeUnionWithBool x = case x of | ||
| 85 | 85 | |
| 86 | 86 | --- encoder helpers |
| 87 | 87 | |
| 88 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 89 | +makeDictEncoder f m r = | |
| 90 | + r | |
| 91 | + |> Dict.toList | |
| 92 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 93 | + |> String.join "," | |
| 94 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 95 | + | |
| 88 | 96 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 89 | 97 | makeNullableEncoder f m = |
| 90 | 98 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/boolean-subschema.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -59,6 +59,14 @@ encodeQuickType x = | ||
| 59 | 59 | |
| 60 | 60 | --- encoder helpers |
| 61 | 61 | |
| 62 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 63 | +makeDictEncoder f m r = | |
| 64 | + r | |
| 65 | + |> Dict.toList | |
| 66 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 67 | + |> String.join "," | |
| 68 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 69 | + | |
| 62 | 70 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 63 | 71 | makeNullableEncoder f m = |
| 64 | 72 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/camelCase.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/schema/class-map-union.schema
Mschema-elmdefault / QuickType.elm+9 −1
| @@ -57,7 +57,7 @@ quickType = | ||
| 57 | 57 | encodeQuickType : QuickType -> Jenc.Value |
| 58 | 58 | encodeQuickType x = |
| 59 | 59 | Jenc.object |
| 60 | - [ ("union", makeNullableEncoder (Jenc.dict identity encodeUnionValue) x.union) | |
| 60 | + [ ("union", makeNullableEncoder (makeDictEncoder identity encodeUnionValue) x.union) | |
| 61 | 61 | ] |
| 62 | 62 | |
| 63 | 63 | unionValue : Jdec.Decoder UnionValue |
| @@ -89,6 +89,14 @@ encodeUnionClass x = | ||
| 89 | 89 | |
| 90 | 90 | --- encoder helpers |
| 91 | 91 | |
| 92 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 93 | +makeDictEncoder f m r = | |
| 94 | + r | |
| 95 | + |> Dict.toList | |
| 96 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 97 | + |> String.join "," | |
| 98 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 99 | + | |
| 92 | 100 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 93 | 101 | makeNullableEncoder f m = |
| 94 | 102 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 125 | 125 | return invalidValue(l(ref || "object"), val, key, parent); |
| 126 | 126 | } |
| 127 | - const result: any = {}; | |
| 127 | + const result: any = Object.create(null); | |
| 128 | 128 | Object.getOwnPropertyNames(props).forEach(key => { |
| 129 | 129 | const prop = props[key]; |
| 130 | 130 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 136 | 136 | } |
| 137 | 137 | }); |
| 138 | - return result; | |
| 138 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 125 | 125 | return invalidValue(l(ref || "object"), val, key, parent); |
| 126 | 126 | } |
| 127 | - const result: any = {}; | |
| 127 | + const result: any = Object.create(null); | |
| 128 | 128 | Object.getOwnPropertyNames(props).forEach(key => { |
| 129 | 129 | const prop = props[key]; |
| 130 | 130 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -135,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 135 | 135 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 136 | 136 | } |
| 137 | 137 | }); |
| 138 | - return result; | |
| 138 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/schema/class-with-additional.schema
Mschema-elmdefault / QuickType.elm+9 −1
| @@ -50,7 +50,7 @@ quickType = | ||
| 50 | 50 | encodeQuickType : QuickType -> Jenc.Value |
| 51 | 51 | encodeQuickType x = |
| 52 | 52 | Jenc.object |
| 53 | - [ ("map", makeNullableEncoder (Jenc.dict identity encodeMap) x.map) | |
| 53 | + [ ("map", makeNullableEncoder (makeDictEncoder identity encodeMap) x.map) | |
| 54 | 54 | ] |
| 55 | 55 | |
| 56 | 56 | map : Jdec.Decoder Map |
| @@ -67,6 +67,14 @@ encodeMap x = case x of | ||
| 67 | 67 | |
| 68 | 68 | --- encoder helpers |
| 69 | 69 | |
| 70 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 71 | +makeDictEncoder f m r = | |
| 72 | + r | |
| 73 | + |> Dict.toList | |
| 74 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 75 | + |> String.join "," | |
| 76 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 77 | + | |
| 70 | 78 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 71 | 79 | makeNullableEncoder f m = |
| 72 | 80 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
5 generated files · +16 −8test/inputs/schema/comment-injection-enum-nested-comment.schema
Mcomment-injection-typescriptdefault / TopLevel.ts+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -78,6 +78,14 @@ encodeKind x = case x of | ||
| 78 | 78 | |
| 79 | 79 | --- encoder helpers |
| 80 | 80 | |
| 81 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 82 | +makeDictEncoder f m r = | |
| 83 | + r | |
| 84 | + |> Dict.toList | |
| 85 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 86 | + |> String.join "," | |
| 87 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 88 | + | |
| 81 | 89 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 82 | 90 | makeNullableEncoder f m = |
| 83 | 91 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 123 | 123 | return invalidValue(l(ref || "object"), val, key, parent); |
| 124 | 124 | } |
| 125 | - const result: any = {}; | |
| 125 | + const result: any = Object.create(null); | |
| 126 | 126 | Object.getOwnPropertyNames(props).forEach(key => { |
| 127 | 127 | const prop = props[key]; |
| 128 | 128 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -133,7 +133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 133 | 133 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 134 | 134 | } |
| 135 | 135 | }); |
| 136 | - return result; | |
| 136 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Test case
5 generated files · +16 −8test/inputs/schema/comment-injection-enum.schema
Mcomment-injection-typescriptdefault / TopLevel.ts+2 −2
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 128 | 128 | return invalidValue(l(ref || "object"), val, key, parent); |
| 129 | 129 | } |
| 130 | - const result: any = {}; | |
| 130 | + const result: any = Object.create(null); | |
| 131 | 131 | Object.getOwnPropertyNames(props).forEach(key => { |
| 132 | 132 | const prop = props[key]; |
| 133 | 133 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 139 | 139 | } |
| 140 | 140 | }); |
| 141 | - return result; | |
| 141 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if (typ === "any") return val; |
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -84,6 +84,14 @@ encodeKind x = case x of | ||
| 84 | 84 | |
| 85 | 85 | --- encoder helpers |
| 86 | 86 | |
| 87 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 88 | +makeDictEncoder f m r = | |
| 89 | + r | |
| 90 | + |> Dict.toList | |
| 91 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 92 | + |> String.join "," | |
| 93 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 94 | + | |
| 87 | 95 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 88 | 96 | makeNullableEncoder f m = |
| 89 | 97 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 129 | 129 | return invalidValue(l(ref || "object"), val, key, parent); |
| 130 | 130 | } |
| 131 | - const result: any = {}; | |
| 131 | + const result: any = Object.create(null); | |
| 132 | 132 | Object.getOwnPropertyNames(props).forEach(key => { |
| 133 | 133 | const prop = props[key]; |
| 134 | 134 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -139,7 +139,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 139 | 139 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 140 | 140 | } |
| 141 | 141 | }); |
| 142 | - return result; | |
| 142 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 128 | 128 | return invalidValue(l(ref || "object"), val, key, parent); |
| 129 | 129 | } |
| 130 | - const result: any = {}; | |
| 130 | + const result: any = Object.create(null); | |
| 131 | 131 | Object.getOwnPropertyNames(props).forEach(key => { |
| 132 | 132 | const prop = props[key]; |
| 133 | 133 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -138,7 +138,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 138 | 138 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 139 | 139 | } |
| 140 | 140 | }); |
| 141 | - return result; | |
| 141 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if (typ === "any") return val; |
Test case
5 generated files · +16 −8test/inputs/schema/comment-injection-nested-comment.schema
Mcomment-injection-typescriptdefault / TopLevel.ts+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -61,6 +61,14 @@ encodeQuickType x = | ||
| 61 | 61 | |
| 62 | 62 | --- encoder helpers |
| 63 | 63 | |
| 64 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 65 | +makeDictEncoder f m r = | |
| 66 | + r | |
| 67 | + |> Dict.toList | |
| 68 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 69 | + |> String.join "," | |
| 70 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 71 | + | |
| 64 | 72 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 65 | 73 | makeNullableEncoder f m = |
| 66 | 74 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 120 | 120 | return invalidValue(l(ref || "object"), val, key, parent); |
| 121 | 121 | } |
| 122 | - const result: any = {}; | |
| 122 | + const result: any = Object.create(null); | |
| 123 | 123 | Object.getOwnPropertyNames(props).forEach(key => { |
| 124 | 124 | const prop = props[key]; |
| 125 | 125 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -130,7 +130,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 130 | 130 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 131 | 131 | } |
| 132 | 132 | }); |
| 133 | - return result; | |
| 133 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (typ === "any") return val; |
Test case
5 generated files · +16 −8test/inputs/schema/comment-injection.schema
Mcomment-injection-typescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -95,6 +95,14 @@ encodeQuickType x = | ||
| 95 | 95 | |
| 96 | 96 | --- encoder helpers |
| 97 | 97 | |
| 98 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 99 | +makeDictEncoder f m r = | |
| 100 | + r | |
| 101 | + |> Dict.toList | |
| 102 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 103 | + |> String.join "," | |
| 104 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 105 | + | |
| 98 | 106 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 99 | 107 | makeNullableEncoder f m = |
| 100 | 108 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 148 | 148 | return invalidValue(l(ref || "object"), val, key, parent); |
| 149 | 149 | } |
| 150 | - const result: any = {}; | |
| 150 | + const result: any = Object.create(null); | |
| 151 | 151 | Object.getOwnPropertyNames(props).forEach(key => { |
| 152 | 152 | const prop = props[key]; |
| 153 | 153 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -158,7 +158,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 158 | 158 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 159 | 159 | } |
| 160 | 160 | }); |
| 161 | - return result; | |
| 161 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/const-non-string.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -79,6 +79,14 @@ encodeKind x = case x of | ||
| 79 | 79 | |
| 80 | 80 | --- encoder helpers |
| 81 | 81 | |
| 82 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 83 | +makeDictEncoder f m r = | |
| 84 | + r | |
| 85 | + |> Dict.toList | |
| 86 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 87 | + |> String.join "," | |
| 88 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 89 | + | |
| 82 | 90 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 83 | 91 | makeNullableEncoder f m = |
| 84 | 92 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/constructor.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -82,6 +82,14 @@ encodeConstructor x = | ||
| 82 | 82 | |
| 83 | 83 | --- encoder helpers |
| 84 | 84 | |
| 85 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 86 | +makeDictEncoder f m r = | |
| 87 | + r | |
| 88 | + |> Dict.toList | |
| 89 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 90 | + |> String.join "," | |
| 91 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 92 | + | |
| 85 | 93 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 86 | 94 | makeNullableEncoder f m = |
| 87 | 95 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/cut-enum.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/date-time-or-string.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/date-time.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -79,6 +79,14 @@ encodeComplexUnionArray x = case x of | ||
| 79 | 79 | |
| 80 | 80 | --- encoder helpers |
| 81 | 81 | |
| 82 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 83 | +makeDictEncoder f m r = | |
| 84 | + r | |
| 85 | + |> Dict.toList | |
| 86 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 87 | + |> String.join "," | |
| 88 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 89 | + | |
| 82 | 90 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 83 | 91 | makeNullableEncoder f m = |
| 84 | 92 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/default-value.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -52,6 +52,14 @@ encodeQuickType x = | ||
| 52 | 52 | |
| 53 | 53 | --- encoder helpers |
| 54 | 54 | |
| 55 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 56 | +makeDictEncoder f m r = | |
| 57 | + r | |
| 58 | + |> Dict.toList | |
| 59 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 60 | + |> String.join "," | |
| 61 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 62 | + | |
| 55 | 63 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 56 | 64 | makeNullableEncoder f m = |
| 57 | 65 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/description-with-double-quotes.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -52,6 +52,14 @@ encodeQuickType x = | ||
| 52 | 52 | |
| 53 | 53 | --- encoder helpers |
| 54 | 54 | |
| 55 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 56 | +makeDictEncoder f m r = | |
| 57 | + r | |
| 58 | + |> Dict.toList | |
| 59 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 60 | + |> String.join "," | |
| 61 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 62 | + | |
| 55 | 63 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 56 | 64 | makeNullableEncoder f m = |
| 57 | 65 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/description.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -151,6 +151,14 @@ encodeUnion x = case x of | ||
| 151 | 151 | |
| 152 | 152 | --- encoder helpers |
| 153 | 153 | |
| 154 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 155 | +makeDictEncoder f m r = | |
| 156 | + r | |
| 157 | + |> Dict.toList | |
| 158 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 159 | + |> String.join "," | |
| 160 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 161 | + | |
| 154 | 162 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 155 | 163 | makeNullableEncoder f m = |
| 156 | 164 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -146,7 +146,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 146 | 146 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 147 | 147 | return invalidValue(l(ref || "object"), val, key, parent); |
| 148 | 148 | } |
| 149 | - const result: any = {}; | |
| 149 | + const result: any = Object.create(null); | |
| 150 | 150 | Object.getOwnPropertyNames(props).forEach(key => { |
| 151 | 151 | const prop = props[key]; |
| 152 | 152 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -157,7 +157,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 157 | 157 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 158 | 158 | } |
| 159 | 159 | }); |
| 160 | - return result; | |
| 160 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -144,7 +144,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 144 | 144 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 145 | 145 | return invalidValue(l(ref || "object"), val, key, parent); |
| 146 | 146 | } |
| 147 | - const result: any = {}; | |
| 147 | + const result: any = Object.create(null); | |
| 148 | 148 | Object.getOwnPropertyNames(props).forEach(key => { |
| 149 | 149 | const prop = props[key]; |
| 150 | 150 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -155,7 +155,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 155 | 155 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 156 | 156 | } |
| 157 | 157 | }); |
| 158 | - return result; | |
| 158 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | if (typ === "any") return val; |
Test case
4 generated files · +16 −8test/inputs/schema/direct-union.schema
Mschema-elmdefault / QuickType.elm+10 −2
| @@ -61,7 +61,7 @@ quickType = | ||
| 61 | 61 | encodeQuickType : QuickType -> Jenc.Value |
| 62 | 62 | encodeQuickType x = |
| 63 | 63 | Jenc.object |
| 64 | - [ ("stuff", Jenc.dict identity encodeThing x.stuff) | |
| 64 | + [ ("stuff", makeDictEncoder identity encodeThing x.stuff) | |
| 65 | 65 | ] |
| 66 | 66 | |
| 67 | 67 | thing : Jdec.Decoder Thing |
| @@ -97,10 +97,18 @@ encodeAnything x = case x of | ||
| 97 | 97 | NullInAnything -> Jenc.null |
| 98 | 98 | StringInAnything y -> Jenc.string y |
| 99 | 99 | DoubleInAnything y -> Jenc.float y |
| 100 | - AnythingMapInAnything y -> Jenc.dict identity identity y | |
| 100 | + AnythingMapInAnything y -> makeDictEncoder identity identity y | |
| 101 | 101 | |
| 102 | 102 | --- encoder helpers |
| 103 | 103 | |
| 104 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 105 | +makeDictEncoder f m r = | |
| 106 | + r | |
| 107 | + |> Dict.toList | |
| 108 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 109 | + |> String.join "," | |
| 110 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 111 | + | |
| 104 | 112 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 105 | 113 | makeNullableEncoder f m = |
| 106 | 114 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/schema/empty-object.schema
Mschema-elmdefault / QuickType.elm+9 −1
| @@ -36,10 +36,18 @@ quickType : Jdec.Decoder QuickType | ||
| 36 | 36 | quickType = Jdec.dict Jdec.value |
| 37 | 37 | |
| 38 | 38 | quickTypeToString : QuickType -> String |
| 39 | -quickTypeToString r = Jenc.encode 0 (Jenc.dict identity identity r) | |
| 39 | +quickTypeToString r = Jenc.encode 0 (makeDictEncoder identity identity r) | |
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/enum-large.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -150,6 +150,14 @@ encodePriority x = case x of | ||
| 150 | 150 | |
| 151 | 151 | --- encoder helpers |
| 152 | 152 | |
| 153 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 154 | +makeDictEncoder f m r = | |
| 155 | + r | |
| 156 | + |> Dict.toList | |
| 157 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 158 | + |> String.join "," | |
| 159 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 160 | + | |
| 153 | 161 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 154 | 162 | makeNullableEncoder f m = |
| 155 | 163 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -136,7 +136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 136 | 136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 137 | 137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 138 | 138 | } |
| 139 | - const result: any = {}; | |
| 139 | + const result: any = Object.create(null); | |
| 140 | 140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 141 | 141 | const prop = props[key]; |
| 142 | 142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -147,7 +147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 147 | 147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 148 | 148 | } |
| 149 | 149 | }); |
| 150 | - return result; | |
| 150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/enum-with-null.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -70,6 +70,14 @@ encodeEnum x = case x of | ||
| 70 | 70 | |
| 71 | 71 | --- encoder helpers |
| 72 | 72 | |
| 73 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 74 | +makeDictEncoder f m r = | |
| 75 | + r | |
| 76 | + |> Dict.toList | |
| 77 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 78 | + |> String.join "," | |
| 79 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 80 | + | |
| 73 | 81 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 74 | 82 | makeNullableEncoder f m = |
| 75 | 83 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/enum-with-values.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -85,6 +85,14 @@ encodeWeekdays x = case x of | ||
| 85 | 85 | |
| 86 | 86 | --- encoder helpers |
| 87 | 87 | |
| 88 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 89 | +makeDictEncoder f m r = | |
| 90 | + r | |
| 91 | + |> Dict.toList | |
| 92 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 93 | + |> String.join "," | |
| 94 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 95 | + | |
| 88 | 96 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 89 | 97 | makeNullableEncoder f m = |
| 90 | 98 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/enum.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -148,6 +148,14 @@ encodeLvc x = case x of | ||
| 148 | 148 | |
| 149 | 149 | --- encoder helpers |
| 150 | 150 | |
| 151 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 152 | +makeDictEncoder f m r = | |
| 153 | + r | |
| 154 | + |> Dict.toList | |
| 155 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 156 | + |> String.join "," | |
| 157 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 158 | + | |
| 151 | 159 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 152 | 160 | makeNullableEncoder f m = |
| 153 | 161 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 130 | 130 | return invalidValue(l(ref || "object"), val, key, parent); |
| 131 | 131 | } |
| 132 | - const result: any = {}; | |
| 132 | + const result: any = Object.create(null); | |
| 133 | 133 | Object.getOwnPropertyNames(props).forEach(key => { |
| 134 | 134 | const prop = props[key]; |
| 135 | 135 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -140,7 +140,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 140 | 140 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 141 | 141 | } |
| 142 | 142 | }); |
| 143 | - return result; | |
| 143 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 121 | 121 | return invalidValue(l(ref || "object"), val, key, parent); |
| 122 | 122 | } |
| 123 | - const result: any = {}; | |
| 123 | + const result: any = Object.create(null); | |
| 124 | 124 | Object.getOwnPropertyNames(props).forEach(key => { |
| 125 | 125 | const prop = props[key]; |
| 126 | 126 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -131,7 +131,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 131 | 131 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | - return result; | |
| 134 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/fractional-bounds.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/schema/go-schema-pattern-properties.schema
Mschema-elmdefault / QuickType.elm+9 −1
| @@ -45,11 +45,19 @@ quickType = | ||
| 45 | 45 | encodeQuickType : QuickType -> Jenc.Value |
| 46 | 46 | encodeQuickType x = |
| 47 | 47 | Jenc.object |
| 48 | - [ ("map", Jenc.dict identity Jenc.int x.map) | |
| 48 | + [ ("map", makeDictEncoder identity Jenc.int x.map) | |
| 49 | 49 | ] |
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/haskell-enum-forbidden.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -70,6 +70,14 @@ encodeHealth x = case x of | ||
| 70 | 70 | |
| 71 | 71 | --- encoder helpers |
| 72 | 72 | |
| 73 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 74 | +makeDictEncoder f m r = | |
| 75 | + r | |
| 76 | + |> Dict.toList | |
| 77 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 78 | + |> String.join "," | |
| 79 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 80 | + | |
| 73 | 81 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 74 | 82 | makeNullableEncoder f m = |
| 75 | 83 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/id-no-address.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/id-root.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/ie-suffix-singularization.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeCookie x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/implicit-all-of.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickType x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/implicit-class-array-union.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -98,6 +98,14 @@ encodeFooClass x = | ||
| 98 | 98 | |
| 99 | 99 | --- encoder helpers |
| 100 | 100 | |
| 101 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 102 | +makeDictEncoder f m r = | |
| 103 | + r | |
| 104 | + |> Dict.toList | |
| 105 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 106 | + |> String.join "," | |
| 107 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 108 | + | |
| 101 | 109 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 102 | 110 | makeNullableEncoder f m = |
| 103 | 111 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/implicit-one-of.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickType x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/integer-before-number.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = case x of | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/integer-float-union.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -67,6 +67,14 @@ encodeNumber x = case x of | ||
| 67 | 67 | |
| 68 | 68 | --- encoder helpers |
| 69 | 69 | |
| 70 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 71 | +makeDictEncoder f m r = | |
| 72 | + r | |
| 73 | + |> Dict.toList | |
| 74 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 75 | + |> String.join "," | |
| 76 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 77 | + | |
| 70 | 78 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 71 | 79 | makeNullableEncoder f m = |
| 72 | 80 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/integer-string.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -85,6 +85,14 @@ encodeUnionWithInt x = case x of | ||
| 85 | 85 | |
| 86 | 86 | --- encoder helpers |
| 87 | 87 | |
| 88 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 89 | +makeDictEncoder f m r = | |
| 90 | + r | |
| 91 | + |> Dict.toList | |
| 92 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 93 | + |> String.join "," | |
| 94 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 95 | + | |
| 88 | 96 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 89 | 97 | makeNullableEncoder f m = |
| 90 | 98 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/integer-type.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -74,6 +74,14 @@ encodeQuickType x = | ||
| 74 | 74 | |
| 75 | 75 | --- encoder helpers |
| 76 | 76 | |
| 77 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 78 | +makeDictEncoder f m r = | |
| 79 | + r | |
| 80 | + |> Dict.toList | |
| 81 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 82 | + |> String.join "," | |
| 83 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 84 | + | |
| 77 | 85 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 78 | 86 | makeNullableEncoder f m = |
| 79 | 87 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 117 | 117 | return invalidValue(l(ref || "object"), val, key, parent); |
| 118 | 118 | } |
| 119 | - const result: any = {}; | |
| 119 | + const result: any = Object.create(null); | |
| 120 | 120 | Object.getOwnPropertyNames(props).forEach(key => { |
| 121 | 121 | const prop = props[key]; |
| 122 | 122 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -127,7 +127,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 127 | 127 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - return result; | |
| 130 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/intersection-nested.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/intersection.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -69,6 +69,14 @@ encodeIntersection x = | ||
| 69 | 69 | |
| 70 | 70 | --- encoder helpers |
| 71 | 71 | |
| 72 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 73 | +makeDictEncoder f m r = | |
| 74 | + r | |
| 75 | + |> Dict.toList | |
| 76 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 77 | + |> String.join "," | |
| 78 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 79 | + | |
| 72 | 80 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 73 | 81 | makeNullableEncoder f m = |
| 74 | 82 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/issue2680-top-level-array.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -40,6 +40,14 @@ quickTypeToString r = Jenc.encode 0 (Jenc.list Jenc.int r) | ||
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/keyword-enum.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -1081,6 +1081,14 @@ encodeEnumEnum x = case x of | ||
| 1081 | 1081 | |
| 1082 | 1082 | --- encoder helpers |
| 1083 | 1083 | |
| 1084 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 1085 | +makeDictEncoder f m r = | |
| 1086 | + r | |
| 1087 | + |> Dict.toList | |
| 1088 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 1089 | + |> String.join "," | |
| 1090 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 1091 | + | |
| 1084 | 1092 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 1085 | 1093 | makeNullableEncoder f m = |
| 1086 | 1094 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -449,7 +449,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 449 | 449 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 450 | 450 | return invalidValue(l(ref || "object"), val, key, parent); |
| 451 | 451 | } |
| 452 | - const result: any = {}; | |
| 452 | + const result: any = Object.create(null); | |
| 453 | 453 | Object.getOwnPropertyNames(props).forEach(key => { |
| 454 | 454 | const prop = props[key]; |
| 455 | 455 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -460,7 +460,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 460 | 460 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 461 | 461 | } |
| 462 | 462 | }); |
| 463 | - return result; | |
| 463 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/keyword-unions.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -11880,6 +11880,14 @@ encodeYield x = | ||
| 11880 | 11880 | |
| 11881 | 11881 | --- encoder helpers |
| 11882 | 11882 | |
| 11883 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 11884 | +makeDictEncoder f m r = | |
| 11885 | + r | |
| 11886 | + |> Dict.toList | |
| 11887 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 11888 | + |> String.join "," | |
| 11889 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 11890 | + | |
| 11883 | 11891 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 11884 | 11892 | makeNullableEncoder f m = |
| 11885 | 11893 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -2136,7 +2136,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 2136 | 2136 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 2137 | 2137 | return invalidValue(l(ref || "object"), val, key, parent); |
| 2138 | 2138 | } |
| 2139 | - const result: any = {}; | |
| 2139 | + const result: any = Object.create(null); | |
| 2140 | 2140 | Object.getOwnPropertyNames(props).forEach(key => { |
| 2141 | 2141 | const prop = props[key]; |
| 2142 | 2142 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -2147,7 +2147,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 2147 | 2147 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 2148 | 2148 | } |
| 2149 | 2149 | }); |
| 2150 | - return result; | |
| 2150 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 2151 | 2151 | } |
| 2152 | 2152 | |
| 2153 | 2153 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -1122,7 +1122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1122 | 1122 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 1123 | 1123 | return invalidValue(l(ref || "object"), val, key, parent); |
| 1124 | 1124 | } |
| 1125 | - const result: any = {}; | |
| 1125 | + const result: any = Object.create(null); | |
| 1126 | 1126 | Object.getOwnPropertyNames(props).forEach(key => { |
| 1127 | 1127 | const prop = props[key]; |
| 1128 | 1128 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -1133,7 +1133,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 1133 | 1133 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 1134 | 1134 | } |
| 1135 | 1135 | }); |
| 1136 | - return result; | |
| 1136 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/light.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -72,6 +72,14 @@ encodeLightParams x = | ||
| 72 | 72 | |
| 73 | 73 | --- encoder helpers |
| 74 | 74 | |
| 75 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 76 | +makeDictEncoder f m r = | |
| 77 | + r | |
| 78 | + |> Dict.toList | |
| 79 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 80 | + |> String.join "," | |
| 81 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 82 | + | |
| 75 | 83 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 76 | 84 | makeNullableEncoder f m = |
| 77 | 85 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/list.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/min-max-items.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -79,6 +79,14 @@ encodeUnionItem x = case x of | ||
| 79 | 79 | |
| 80 | 80 | --- encoder helpers |
| 81 | 81 | |
| 82 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 83 | +makeDictEncoder f m r = | |
| 84 | + r | |
| 85 | + |> Dict.toList | |
| 86 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 87 | + |> String.join "," | |
| 88 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 89 | + | |
| 82 | 90 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 83 | 91 | makeNullableEncoder f m = |
| 84 | 92 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -114,7 +114,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 114 | 114 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 115 | 115 | return invalidValue(l(ref || "object"), val, key, parent); |
| 116 | 116 | } |
| 117 | - const result: any = {}; | |
| 117 | + const result: any = Object.create(null); | |
| 118 | 118 | Object.getOwnPropertyNames(props).forEach(key => { |
| 119 | 119 | const prop = props[key]; |
| 120 | 120 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -125,7 +125,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 125 | 125 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 126 | 126 | } |
| 127 | 127 | }); |
| 128 | - return result; | |
| 128 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/minmax-integer.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -71,6 +71,14 @@ encodeQuickType x = | ||
| 71 | 71 | |
| 72 | 72 | --- encoder helpers |
| 73 | 73 | |
| 74 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 75 | +makeDictEncoder f m r = | |
| 76 | + r | |
| 77 | + |> Dict.toList | |
| 78 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 79 | + |> String.join "," | |
| 80 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 81 | + | |
| 74 | 82 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 75 | 83 | makeNullableEncoder f m = |
| 76 | 84 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/minmax.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -71,6 +71,14 @@ encodeQuickType x = | ||
| 71 | 71 | |
| 72 | 72 | --- encoder helpers |
| 73 | 73 | |
| 74 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 75 | +makeDictEncoder f m r = | |
| 76 | + r | |
| 77 | + |> Dict.toList | |
| 78 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 79 | + |> String.join "," | |
| 80 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 81 | + | |
| 74 | 82 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 75 | 83 | makeNullableEncoder f m = |
| 76 | 84 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/minmaxlength.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -88,6 +88,14 @@ encodeInUnion x = case x of | ||
| 88 | 88 | |
| 89 | 89 | --- encoder helpers |
| 90 | 90 | |
| 91 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 92 | +makeDictEncoder f m r = | |
| 93 | + r | |
| 94 | + |> Dict.toList | |
| 95 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 96 | + |> String.join "," | |
| 97 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 98 | + | |
| 91 | 99 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 92 | 100 | makeNullableEncoder f m = |
| 93 | 101 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/multi-type-enum.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -96,6 +96,14 @@ encodeFooEnum x = case x of | ||
| 96 | 96 | |
| 97 | 97 | --- encoder helpers |
| 98 | 98 | |
| 99 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 100 | +makeDictEncoder f m r = | |
| 101 | + r | |
| 102 | + |> Dict.toList | |
| 103 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 104 | + |> String.join "," | |
| 105 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 106 | + | |
| 99 | 107 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 100 | 108 | makeNullableEncoder f m = |
| 101 | 109 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/mutually-recursive.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/nested-intersection-union.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -75,6 +75,14 @@ encodeItem x = | ||
| 75 | 75 | |
| 76 | 76 | --- encoder helpers |
| 77 | 77 | |
| 78 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 79 | +makeDictEncoder f m r = | |
| 80 | + r | |
| 81 | + |> Dict.toList | |
| 82 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 83 | + |> String.join "," | |
| 84 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 85 | + | |
| 78 | 86 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 79 | 87 | makeNullableEncoder f m = |
| 80 | 88 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/non-standard-ref.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickType x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/nullable-optional-one-of.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -73,6 +73,14 @@ encodeKind x = case x of | ||
| 73 | 73 | |
| 74 | 74 | --- encoder helpers |
| 75 | 75 | |
| 76 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 77 | +makeDictEncoder f m r = | |
| 78 | + r | |
| 79 | + |> Dict.toList | |
| 80 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 81 | + |> String.join "," | |
| 82 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 83 | + | |
| 76 | 84 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 77 | 85 | makeNullableEncoder f m = |
| 78 | 86 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/object-type-required.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -71,6 +71,14 @@ encodeEmpty x = | ||
| 71 | 71 | |
| 72 | 72 | --- encoder helpers |
| 73 | 73 | |
| 74 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 75 | +makeDictEncoder f m r = | |
| 76 | + r | |
| 77 | + |> Dict.toList | |
| 78 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 79 | + |> String.join "," | |
| 80 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 81 | + | |
| 74 | 82 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 75 | 83 | makeNullableEncoder f m = |
| 76 | 84 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/optional-any.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/optional-const-ref.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -87,6 +87,14 @@ encodeCoordinate x = | ||
| 87 | 87 | |
| 88 | 88 | --- encoder helpers |
| 89 | 89 | |
| 90 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 91 | +makeDictEncoder f m r = | |
| 92 | + r | |
| 93 | + |> Dict.toList | |
| 94 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 95 | + |> String.join "," | |
| 96 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 97 | + | |
| 90 | 98 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 91 | 99 | makeNullableEncoder f m = |
| 92 | 100 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 119 | 119 | return invalidValue(l(ref || "object"), val, key, parent); |
| 120 | 120 | } |
| 121 | - const result: any = {}; | |
| 121 | + const result: any = Object.create(null); | |
| 122 | 122 | Object.getOwnPropertyNames(props).forEach(key => { |
| 123 | 123 | const prop = props[key]; |
| 124 | 124 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 130 | 130 | } |
| 131 | 131 | }); |
| 132 | - return result; | |
| 132 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 119 | 119 | return invalidValue(l(ref || "object"), val, key, parent); |
| 120 | 120 | } |
| 121 | - const result: any = {}; | |
| 121 | + const result: any = Object.create(null); | |
| 122 | 122 | Object.getOwnPropertyNames(props).forEach(key => { |
| 123 | 123 | const prop = props[key]; |
| 124 | 124 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 130 | 130 | } |
| 131 | 131 | }); |
| 132 | - return result; | |
| 132 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/optional-constraints.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickType x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/optional-date-time.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -65,6 +65,14 @@ encodeQuickType x = | ||
| 65 | 65 | |
| 66 | 66 | --- encoder helpers |
| 67 | 67 | |
| 68 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 69 | +makeDictEncoder f m r = | |
| 70 | + r | |
| 71 | + |> Dict.toList | |
| 72 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 73 | + |> String.join "," | |
| 74 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 75 | + | |
| 68 | 76 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 69 | 77 | makeNullableEncoder f m = |
| 70 | 78 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/optional-enum.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -73,6 +73,14 @@ encodeShortcut x = case x of | ||
| 73 | 73 | |
| 74 | 74 | --- encoder helpers |
| 75 | 75 | |
| 76 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 77 | +makeDictEncoder f m r = | |
| 78 | + r | |
| 79 | + |> Dict.toList | |
| 80 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 81 | + |> String.join "," | |
| 82 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 83 | + | |
| 76 | 84 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 77 | 85 | makeNullableEncoder f m = |
| 78 | 86 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/optional-property.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -107,7 +107,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 107 | 107 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 108 | 108 | return invalidValue(l(ref || "object"), val, key, parent); |
| 109 | 109 | } |
| 110 | - const result: any = {}; | |
| 110 | + const result: any = Object.create(null); | |
| 111 | 111 | Object.getOwnPropertyNames(props).forEach(key => { |
| 112 | 112 | const prop = props[key]; |
| 113 | 113 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 119 | 119 | } |
| 120 | 120 | }); |
| 121 | - return result; | |
| 121 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/pattern.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -75,6 +75,14 @@ encodeRegExp x = | ||
| 75 | 75 | |
| 76 | 76 | --- encoder helpers |
| 77 | 77 | |
| 78 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 79 | +makeDictEncoder f m r = | |
| 80 | + r | |
| 81 | + |> Dict.toList | |
| 82 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 83 | + |> String.join "," | |
| 84 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 85 | + | |
| 78 | 86 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 79 | 87 | makeNullableEncoder f m = |
| 80 | 88 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -115,7 +115,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 115 | 115 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 116 | 116 | return invalidValue(l(ref || "object"), val, key, parent); |
| 117 | 117 | } |
| 118 | - const result: any = {}; | |
| 118 | + const result: any = Object.create(null); | |
| 119 | 119 | Object.getOwnPropertyNames(props).forEach(key => { |
| 120 | 120 | const prop = props[key]; |
| 121 | 121 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | - return result; | |
| 129 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/postman-collection.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 119 | 119 | return invalidValue(l(ref || "object"), val, key, parent); |
| 120 | 120 | } |
| 121 | - const result: any = {}; | |
| 121 | + const result: any = Object.create(null); | |
| 122 | 122 | Object.getOwnPropertyNames(props).forEach(key => { |
| 123 | 123 | const prop = props[key]; |
| 124 | 124 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 130 | 130 | } |
| 131 | 131 | }); |
| 132 | - return result; | |
| 132 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 119 | 119 | return invalidValue(l(ref || "object"), val, key, parent); |
| 120 | 120 | } |
| 121 | - const result: any = {}; | |
| 121 | + const result: any = Object.create(null); | |
| 122 | 122 | Object.getOwnPropertyNames(props).forEach(key => { |
| 123 | 123 | const prop = props[key]; |
| 124 | 124 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 130 | 130 | } |
| 131 | 131 | }); |
| 132 | - return result; | |
| 132 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/prefix-items.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -70,6 +70,14 @@ encodeOpen x = case x of | ||
| 70 | 70 | |
| 71 | 71 | --- encoder helpers |
| 72 | 72 | |
| 73 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 74 | +makeDictEncoder f m r = | |
| 75 | + r | |
| 76 | + |> Dict.toList | |
| 77 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 78 | + |> String.join "," | |
| 79 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 80 | + | |
| 73 | 81 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 74 | 82 | makeNullableEncoder f m = |
| 75 | 83 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/recursive-union-flattening.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 122 | 122 | return invalidValue(l(ref || "object"), val, key, parent); |
| 123 | 123 | } |
| 124 | - const result: any = {}; | |
| 124 | + const result: any = Object.create(null); | |
| 125 | 125 | Object.getOwnPropertyNames(props).forEach(key => { |
| 126 | 126 | const prop = props[key]; |
| 127 | 127 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -132,7 +132,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 132 | 132 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 133 | 133 | } |
| 134 | 134 | }); |
| 135 | - return result; | |
| 135 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/ref-id-files.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/ref-remote.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/renaming-bug.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -385,6 +385,14 @@ encodeName x = case x of | ||
| 385 | 385 | |
| 386 | 386 | --- encoder helpers |
| 387 | 387 | |
| 388 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 389 | +makeDictEncoder f m r = | |
| 390 | + r | |
| 391 | + |> Dict.toList | |
| 392 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 393 | + |> String.join "," | |
| 394 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 395 | + | |
| 388 | 396 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 389 | 397 | makeNullableEncoder f m = |
| 390 | 398 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -210,7 +210,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 210 | 210 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 211 | 211 | return invalidValue(l(ref || "object"), val, key, parent); |
| 212 | 212 | } |
| 213 | - const result: any = {}; | |
| 213 | + const result: any = Object.create(null); | |
| 214 | 214 | Object.getOwnPropertyNames(props).forEach(key => { |
| 215 | 215 | const prop = props[key]; |
| 216 | 216 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -221,7 +221,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 221 | 221 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 222 | 222 | } |
| 223 | 223 | }); |
| 224 | - return result; | |
| 224 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -195,7 +195,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 195 | 195 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 196 | 196 | return invalidValue(l(ref || "object"), val, key, parent); |
| 197 | 197 | } |
| 198 | - const result: any = {}; | |
| 198 | + const result: any = Object.create(null); | |
| 199 | 199 | Object.getOwnPropertyNames(props).forEach(key => { |
| 200 | 200 | const prop = props[key]; |
| 201 | 201 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -206,7 +206,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 206 | 206 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 207 | 207 | } |
| 208 | 208 | }); |
| 209 | - return result; | |
| 209 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/required-draft3.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/required-non-properties.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/required.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/rust-cycle-breaker-union.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/schema-constraints.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -53,6 +53,14 @@ encodeQuickType x = | ||
| 53 | 53 | |
| 54 | 54 | --- encoder helpers |
| 55 | 55 | |
| 56 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 57 | +makeDictEncoder f m r = | |
| 58 | + r | |
| 59 | + |> Dict.toList | |
| 60 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 61 | + |> String.join "," | |
| 62 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 63 | + | |
| 56 | 64 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 57 | 65 | makeNullableEncoder f m = |
| 58 | 66 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -109,7 +109,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 109 | 109 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 110 | 110 | return invalidValue(l(ref || "object"), val, key, parent); |
| 111 | 111 | } |
| 112 | - const result: any = {}; | |
| 112 | + const result: any = Object.create(null); | |
| 113 | 113 | Object.getOwnPropertyNames(props).forEach(key => { |
| 114 | 114 | const prop = props[key]; |
| 115 | 115 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -120,7 +120,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 120 | 120 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 121 | 121 | } |
| 122 | 122 | }); |
| 123 | - return result; | |
| 123 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/simple-ref.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/strict-optional.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -50,6 +50,14 @@ encodeQuickType x = | ||
| 50 | 50 | |
| 51 | 51 | --- encoder helpers |
| 52 | 52 | |
| 53 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 54 | +makeDictEncoder f m r = | |
| 55 | + r | |
| 56 | + |> Dict.toList | |
| 57 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 58 | + |> String.join "," | |
| 59 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 60 | + | |
| 53 | 61 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 54 | 62 | makeNullableEncoder f m = |
| 55 | 63 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/top-level-array.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -59,6 +59,14 @@ encodeTextClassificationOutputElement x = | ||
| 59 | 59 | |
| 60 | 60 | --- encoder helpers |
| 61 | 61 | |
| 62 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 63 | +makeDictEncoder f m r = | |
| 64 | + r | |
| 65 | + |> Dict.toList | |
| 66 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 67 | + |> String.join "," | |
| 68 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 69 | + | |
| 62 | 70 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 63 | 71 | makeNullableEncoder f m = |
| 64 | 72 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -111,7 +111,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 111 | 111 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 112 | 112 | return invalidValue(l(ref || "object"), val, key, parent); |
| 113 | 113 | } |
| 114 | - const result: any = {}; | |
| 114 | + const result: any = Object.create(null); | |
| 115 | 115 | Object.getOwnPropertyNames(props).forEach(key => { |
| 116 | 116 | const prop = props[key]; |
| 117 | 117 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -122,7 +122,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 122 | 122 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 123 | 123 | } |
| 124 | 124 | }); |
| 125 | - return result; | |
| 125 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/top-level-enum.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -57,6 +57,14 @@ encodeQuickType x = case x of | ||
| 57 | 57 | |
| 58 | 58 | --- encoder helpers |
| 59 | 59 | |
| 60 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 61 | +makeDictEncoder f m r = | |
| 62 | + r | |
| 63 | + |> Dict.toList | |
| 64 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 65 | + |> String.join "," | |
| 66 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 67 | + | |
| 60 | 68 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 61 | 69 | makeNullableEncoder f m = |
| 62 | 70 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/top-level-primitive-array.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -40,6 +40,14 @@ quickTypeToString r = Jenc.encode 0 (Jenc.list Jenc.string r) | ||
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -105,7 +105,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 105 | 105 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 106 | 106 | return invalidValue(l(ref || "object"), val, key, parent); |
| 107 | 107 | } |
| 108 | - const result: any = {}; | |
| 108 | + const result: any = Object.create(null); | |
| 109 | 109 | Object.getOwnPropertyNames(props).forEach(key => { |
| 110 | 110 | const prop = props[key]; |
| 111 | 111 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -116,7 +116,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 116 | 116 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 117 | 117 | } |
| 118 | 118 | }); |
| 119 | - return result; | |
| 119 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/top-level-primitive.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -40,6 +40,14 @@ quickTypeToString r = Jenc.encode 0 (Jenc.float r) | ||
| 40 | 40 | |
| 41 | 41 | --- encoder helpers |
| 42 | 42 | |
| 43 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 44 | +makeDictEncoder f m r = | |
| 45 | + r | |
| 46 | + |> Dict.toList | |
| 47 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 48 | + |> String.join "," | |
| 49 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 50 | + | |
| 43 | 51 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 44 | 52 | makeNullableEncoder f m = |
| 45 | 53 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -108,7 +108,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 108 | 108 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 109 | 109 | return invalidValue(l(ref || "object"), val, key, parent); |
| 110 | 110 | } |
| 111 | - const result: any = {}; | |
| 111 | + const result: any = Object.create(null); | |
| 112 | 112 | Object.getOwnPropertyNames(props).forEach(key => { |
| 113 | 113 | const prop = props[key]; |
| 114 | 114 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -119,7 +119,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 119 | 119 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 120 | 120 | } |
| 121 | 121 | }); |
| 122 | - return result; | |
| 122 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/tuple.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -67,6 +67,14 @@ encodeTuple x = case x of | ||
| 67 | 67 | |
| 68 | 68 | --- encoder helpers |
| 69 | 69 | |
| 70 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 71 | +makeDictEncoder f m r = | |
| 72 | + r | |
| 73 | + |> Dict.toList | |
| 74 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 75 | + |> String.join "," | |
| 76 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 77 | + | |
| 70 | 78 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 71 | 79 | makeNullableEncoder f m = |
| 72 | 80 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +15 −7test/inputs/schema/unevaluated-properties.schema
Mschema-elmdefault / QuickType.elm+9 −1
| @@ -88,7 +88,7 @@ encodeConfig x = | ||
| 88 | 88 | Jenc.object |
| 89 | 89 | [ ("closed", makeNullableEncoder encodeClosed x.closed) |
| 90 | 90 | , ("name", makeNullableEncoder Jenc.string x.name) |
| 91 | - , ("settings", makeNullableEncoder (Jenc.dict identity (Jenc.list encodeItem)) x.settings) | |
| 91 | + , ("settings", makeNullableEncoder (makeDictEncoder identity (Jenc.list encodeItem)) x.settings) | |
| 92 | 92 | ] |
| 93 | 93 | |
| 94 | 94 | closed : Jdec.Decoder Closed |
| @@ -138,6 +138,14 @@ encodeItem x = | ||
| 138 | 138 | |
| 139 | 139 | --- encoder helpers |
| 140 | 140 | |
| 141 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 142 | +makeDictEncoder f m r = | |
| 143 | + r | |
| 144 | + |> Dict.toList | |
| 145 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 146 | + |> String.join "," | |
| 147 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 148 | + | |
| 141 | 149 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 142 | 150 | makeNullableEncoder f m = |
| 143 | 151 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -126,7 +126,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 126 | 126 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 127 | 127 | return invalidValue(l(ref || "object"), val, key, parent); |
| 128 | 128 | } |
| 129 | - const result: any = {}; | |
| 129 | + const result: any = Object.create(null); | |
| 130 | 130 | Object.getOwnPropertyNames(props).forEach(key => { |
| 131 | 131 | const prop = props[key]; |
| 132 | 132 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -137,7 +137,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 137 | 137 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 138 | 138 | } |
| 139 | 139 | }); |
| 140 | - return result; | |
| 140 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 124 | 124 | return invalidValue(l(ref || "object"), val, key, parent); |
| 125 | 125 | } |
| 126 | - const result: any = {}; | |
| 126 | + const result: any = Object.create(null); | |
| 127 | 127 | Object.getOwnPropertyNames(props).forEach(key => { |
| 128 | 128 | const prop = props[key]; |
| 129 | 129 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -134,7 +134,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 134 | 134 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 135 | 135 | } |
| 136 | 136 | }); |
| 137 | - return result; | |
| 137 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/unicode-codepoint-length.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -56,6 +56,14 @@ encodeQuickType x = | ||
| 56 | 56 | |
| 57 | 57 | --- encoder helpers |
| 58 | 58 | |
| 59 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 60 | +makeDictEncoder f m r = | |
| 61 | + r | |
| 62 | + |> Dict.toList | |
| 63 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 64 | + |> String.join "," | |
| 65 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 66 | + | |
| 59 | 67 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 60 | 68 | makeNullableEncoder f m = |
| 61 | 69 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/union-int-double.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -70,6 +70,14 @@ encodeValue x = case x of | ||
| 70 | 70 | |
| 71 | 71 | --- encoder helpers |
| 72 | 72 | |
| 73 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 74 | +makeDictEncoder f m r = | |
| 75 | + r | |
| 76 | + |> Dict.toList | |
| 77 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 78 | + |> String.join "," | |
| 79 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 80 | + | |
| 73 | 81 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 74 | 82 | makeNullableEncoder f m = |
| 75 | 83 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 110 | 110 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 111 | 111 | return invalidValue(l(ref || "object"), val, key, parent); |
| 112 | 112 | } |
| 113 | - const result: any = {}; | |
| 113 | + const result: any = Object.create(null); | |
| 114 | 114 | Object.getOwnPropertyNames(props).forEach(key => { |
| 115 | 115 | const prop = props[key]; |
| 116 | 116 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -121,7 +121,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 121 | 121 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 122 | 122 | } |
| 123 | 123 | }); |
| 124 | - return result; | |
| 124 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/union-list.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -113,7 +113,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 113 | 113 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 114 | 114 | return invalidValue(l(ref || "object"), val, key, parent); |
| 115 | 115 | } |
| 116 | - const result: any = {}; | |
| 116 | + const result: any = Object.create(null); | |
| 117 | 117 | Object.getOwnPropertyNames(props).forEach(key => { |
| 118 | 118 | const prop = props[key]; |
| 119 | 119 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -124,7 +124,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 124 | 124 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 125 | 125 | } |
| 126 | 126 | }); |
| 127 | - return result; | |
| 127 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/union.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -62,6 +62,14 @@ encodeQuickTypeElement x = | ||
| 62 | 62 | |
| 63 | 63 | --- encoder helpers |
| 64 | 64 | |
| 65 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 66 | +makeDictEncoder f m r = | |
| 67 | + r | |
| 68 | + |> Dict.toList | |
| 69 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 70 | + |> String.join "," | |
| 71 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 72 | + | |
| 65 | 73 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 66 | 74 | makeNullableEncoder f m = |
| 67 | 75 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -112,7 +112,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 112 | 112 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 113 | 113 | return invalidValue(l(ref || "object"), val, key, parent); |
| 114 | 114 | } |
| 115 | - const result: any = {}; | |
| 115 | + const result: any = Object.create(null); | |
| 116 | 116 | Object.getOwnPropertyNames(props).forEach(key => { |
| 117 | 117 | const prop = props[key]; |
| 118 | 118 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -123,7 +123,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 123 | 123 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 124 | 124 | } |
| 125 | 125 | }); |
| 126 | - return result; | |
| 126 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (typ === "any") return val; |
Test case
4 generated files · +14 −6test/inputs/schema/uuid.schema
Mschema-elmdefault / QuickType.elm+8 −0
| @@ -65,6 +65,14 @@ encodeQuickType x = | ||
| 65 | 65 | |
| 66 | 66 | --- encoder helpers |
| 67 | 67 | |
| 68 | +makeDictEncoder : (String -> String) -> (a -> Jenc.Value) -> Dict String a -> Jenc.Value | |
| 69 | +makeDictEncoder f m r = | |
| 70 | + r | |
| 71 | + |> Dict.toList | |
| 72 | + |> List.map (\( x, y ) -> Jenc.encode 0 (Jenc.string (f x)) ++ ":" ++ Jenc.encode 0 (m y)) | |
| 73 | + |> String.join "," | |
| 74 | + |> (\str -> Jdec.decodeString Jdec.value ("{" ++ str ++ "}") |> Result.withDefault Jenc.null) | |
| 75 | + | |
| 68 | 76 | makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value |
| 69 | 77 | makeNullableEncoder f m = |
| 70 | 78 | case m of |
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -118,7 +118,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 118 | 118 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 119 | 119 | return invalidValue(l(ref || "object"), val, key, parent); |
| 120 | 120 | } |
| 121 | - const result: any = {}; | |
| 121 | + const result: any = Object.create(null); | |
| 122 | 122 | Object.getOwnPropertyNames(props).forEach(key => { |
| 123 | 123 | const prop = props[key]; |
| 124 | 124 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -129,7 +129,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 129 | 129 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 130 | 130 | } |
| 131 | 131 | }); |
| 132 | - return result; | |
| 132 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -117,7 +117,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 117 | 117 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 118 | 118 | return invalidValue(l(ref || "object"), val, key, parent); |
| 119 | 119 | } |
| 120 | - const result: any = {}; | |
| 120 | + const result: any = Object.create(null); | |
| 121 | 121 | Object.getOwnPropertyNames(props).forEach(key => { |
| 122 | 122 | const prop = props[key]; |
| 123 | 123 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -128,7 +128,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 128 | 128 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 129 | 129 | } |
| 130 | 130 | }); |
| 131 | - return result; | |
| 131 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (typ === "any") return val; |
Test case
3 generated files · +6 −6test/inputs/schema/vega-lite.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -6199,7 +6199,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 6199 | 6199 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 6200 | 6200 | return invalidValue(l(ref || "object"), val, key, parent); |
| 6201 | 6201 | } |
| 6202 | - const result: any = {}; | |
| 6202 | + const result: any = Object.create(null); | |
| 6203 | 6203 | Object.getOwnPropertyNames(props).forEach(key => { |
| 6204 | 6204 | const prop = props[key]; |
| 6205 | 6205 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -6210,7 +6210,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 6210 | 6210 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 6211 | 6211 | } |
| 6212 | 6212 | }); |
| 6213 | - return result; | |
| 6213 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 6214 | 6214 | } |
| 6215 | 6215 | |
| 6216 | 6216 | if (typ === "any") return val; |
Mschema-javascriptdefault / TopLevel.js+2 −2
| @@ -101,7 +101,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 101 | 101 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 102 | 102 | return invalidValue(l(ref || "object"), val, key, parent); |
| 103 | 103 | } |
| 104 | - const result = {}; | |
| 104 | + const result = Object.create(null); | |
| 105 | 105 | Object.getOwnPropertyNames(props).forEach(key => { |
| 106 | 106 | const prop = props[key]; |
| 107 | 107 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -112,7 +112,7 @@ function transform(val, typ, getProps, key = '', parent = '') { | ||
| 112 | 112 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 113 | 113 | } |
| 114 | 114 | }); |
| 115 | - return result; | |
| 115 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if (typ === "any") return val; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -5956,7 +5956,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 5956 | 5956 | if (val === null || typeof val !== "object" || Array.isArray(val)) { |
| 5957 | 5957 | return invalidValue(l(ref || "object"), val, key, parent); |
| 5958 | 5958 | } |
| 5959 | - const result: any = {}; | |
| 5959 | + const result: any = Object.create(null); | |
| 5960 | 5960 | Object.getOwnPropertyNames(props).forEach(key => { |
| 5961 | 5961 | const prop = props[key]; |
| 5962 | 5962 | const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; |
| @@ -5967,7 +5967,7 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any | ||
| 5967 | 5967 | result[key] = transform(val[key], additional, getProps, key, ref); |
| 5968 | 5968 | } |
| 5969 | 5969 | }); |
| 5970 | - return result; | |
| 5970 | + return Object.setPrototypeOf(result, Object.prototype); | |
| 5971 | 5971 | } |
| 5972 | 5972 | |
| 5973 | 5973 | if (typ === "any") return val; |
No generated files match these filters.