diff --git a/CHANGELOG.md b/CHANGELOG.md index f33dd3c8..630792de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# Next + +- **[Fix]** Use `{}` instead of `Object.create(null)` when creating new objects in `DocumentType`. + Quickfix for [chaijs/deep-eql#51](https://github.com/chaijs/deep-eql/issues/51). + # 0.6.0 (2018-01-29) - **[Breaking change]** Remove index module, you need to import specific modules with deep imports diff --git a/src/lib/bson/document.ts b/src/lib/bson/document.ts index 9384f977..53f38ce5 100644 --- a/src/lib/bson/document.ts +++ b/src/lib/bson/document.ts @@ -4,7 +4,7 @@ import { DocumentType, name as typeName, PropertyDescriptor, renameKeys } from " export function register(serializer: Serializer): void { function write(type: DocumentType, val: T): any { - const result: any = Object.create(null); + const result: any = {}; // Object.create(null); for (const [key, outKey] of renameKeys(type.properties, type.rename)) { const descriptor: PropertyDescriptor = type.properties[key]; const value: T[keyof T] = val[key]; @@ -22,7 +22,7 @@ export function register(serializer: Serializer): void { const missing: Set = new Set(); const invalid: Map = new Map(); - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const [key, outKey] of renameKeys(type.properties, type.rename)) { if (extra !== undefined) { @@ -52,7 +52,7 @@ export function register(serializer: Serializer): void { } function readTrusted(type: DocumentType, input: any): T { - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const [key, outKey] of renameKeys(type.properties, type.rename)) { const descriptor: PropertyDescriptor = type.properties[key]; const outValue: any = Reflect.get(input, outKey); diff --git a/src/lib/qs/document.ts b/src/lib/qs/document.ts index 9384f977..53f38ce5 100644 --- a/src/lib/qs/document.ts +++ b/src/lib/qs/document.ts @@ -4,7 +4,7 @@ import { DocumentType, name as typeName, PropertyDescriptor, renameKeys } from " export function register(serializer: Serializer): void { function write(type: DocumentType, val: T): any { - const result: any = Object.create(null); + const result: any = {}; // Object.create(null); for (const [key, outKey] of renameKeys(type.properties, type.rename)) { const descriptor: PropertyDescriptor = type.properties[key]; const value: T[keyof T] = val[key]; @@ -22,7 +22,7 @@ export function register(serializer: Serializer): void { const missing: Set = new Set(); const invalid: Map = new Map(); - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const [key, outKey] of renameKeys(type.properties, type.rename)) { if (extra !== undefined) { @@ -52,7 +52,7 @@ export function register(serializer: Serializer): void { } function readTrusted(type: DocumentType, input: any): T { - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const [key, outKey] of renameKeys(type.properties, type.rename)) { const descriptor: PropertyDescriptor = type.properties[key]; const outValue: any = Reflect.get(input, outKey); diff --git a/src/lib/types/document.ts b/src/lib/types/document.ts index 90cdd08f..f99567b6 100644 --- a/src/lib/types/document.ts +++ b/src/lib/types/document.ts @@ -105,7 +105,7 @@ export const DocumentType: DocumentTypeConstructor = class { } readTrustedJson(input: any): T { - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const [key, outKey] of this.keys) { const descriptor: PropertyDescriptor = this.properties[key]; const jsonValue: any = Reflect.get(input, outKey); @@ -123,7 +123,7 @@ export const DocumentType: DocumentTypeConstructor = class { const missing: Set = new Set(); const invalid: Map = new Map(); - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const [key, outKey] of this.keys) { if (extra !== undefined) { @@ -153,7 +153,7 @@ export const DocumentType: DocumentTypeConstructor = class { } writeJson(val: T): any { - const result: any = Object.create(null); + const result: any = {}; // Object.create(null); for (const [key, outKey] of this.keys) { const descriptor: PropertyDescriptor = this.properties[key]; const value: T[keyof T] = val[key]; @@ -244,7 +244,7 @@ export const DocumentType: DocumentTypeConstructor = class { } clone(val: T): T { - const result: Partial = Object.create(null); + const result: Partial = {}; // Object.create(null); for (const key in this.properties) { result[key] = val[key] === undefined ? undefined : this.properties[key].type.clone(val[key]); }