From c7138183bb6a573029016ae4cf655a37f4d29b35 Mon Sep 17 00:00:00 2001 From: Chris Pinola Date: Thu, 11 Jun 2020 13:25:37 -0400 Subject: [PATCH 1/2] Prevent config.parse() output from being used as input --- packages/core/src/config.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 886a355f..fd43aaf5 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -66,6 +66,13 @@ export function parse(TRoot: IClassType, actual: any, base?: Partial): } } + if (isSection(actual)) { + throw new Error( + "The value of `actual` has no enumerable properties. Make sure the object being " + + "passed is not the output of `config.parse()` (i.e. does not have the '@section' decorator)." + ); + } + const instance = new TRoot(); if (verifyIsSection(instance)) { const config: T & ISection = new TRoot() as any; @@ -303,8 +310,12 @@ interface ISection { readonly __extensible?: boolean; } +function isSection(obj: any): obj is ISection { + return obj && obj.__assignedProperties; +} + function verifyIsSection(obj: any): obj is ISection { - if (obj && obj.__assignedProperties) { + if (isSection(obj)) { return true; } From ce95c3e94af8c2a08a1c7acd0e3261e035a30b96 Mon Sep 17 00:00:00 2001 From: Chris Pinola Date: Thu, 11 Jun 2020 13:26:02 -0400 Subject: [PATCH 2/2] Bump package version --- packages/core/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index 6952f2e3..abb5a6f0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@walmartlabs/cookie-cutter-core", - "version": "1.3.0-beta.4", + "version": "1.3.0-beta.5", "license": "Apache-2.0", "main": "dist/index.js", "types": "dist/index.d.ts",