From 8ced3385932a430981248e77f0088a92c614d7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Thu, 28 Mar 2019 19:05:16 +0100 Subject: [PATCH] fix(kernel): Transitively consider properties when deserializing structs --- packages/jsii-kernel/lib/serialization.ts | 17 ++++++++++++++--- packages/jsii-runtime/webpack.config.js | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/jsii-kernel/lib/serialization.ts b/packages/jsii-kernel/lib/serialization.ts index e91c524404..9741c86830 100644 --- a/packages/jsii-kernel/lib/serialization.ts +++ b/packages/jsii-kernel/lib/serialization.ts @@ -289,7 +289,7 @@ export const SERIALIZERS: {[k: string]: Serializer} = { } const namedType = host.lookupType((type as spec.NamedTypeReference).fqn); - const props = propertiesOf(namedType); + const props = propertiesOf(namedType, host.lookupType); return mapValues(value, (v, key) => { if (!props[key]) { return undefined; } // Don't map if unknown property @@ -540,13 +540,24 @@ function mapValues(value: unknown, fn: (value: any, field: string) => any) { return out; } -function propertiesOf(t: spec.Type): {[name: string]: spec.Property} { +function propertiesOf(t: spec.Type, lookup: TypeLookup): {[name: string]: spec.Property} { if (!spec.isClassOrInterfaceType(t)) { return {}; } - const ret: {[name: string]: spec.Property} = {}; + let ret: { [name: string]: spec.Property } = {}; + + if (t.interfaces) { + for (const iface of t.interfaces) { + ret = { ...ret, ...propertiesOf(lookup(iface.fqn), lookup) }; + } + } + if (spec.isClassType(t) && t.base) { + ret = { ...ret, ...propertiesOf(lookup(t.base.fqn), lookup) }; + } + for (const prop of t.properties || []) { ret[prop.name] = prop; } + return ret; } diff --git a/packages/jsii-runtime/webpack.config.js b/packages/jsii-runtime/webpack.config.js index e808df74cc..097d7e95f7 100644 --- a/packages/jsii-runtime/webpack.config.js +++ b/packages/jsii-runtime/webpack.config.js @@ -23,5 +23,8 @@ module.exports = { use: ['source-map-loader'], enforce: 'pre' }] + }, + optimization: { + minimize: false } }