Skip to content

Commit

Permalink
fix(kernel): Transitively consider properties when deserializing stru…
Browse files Browse the repository at this point in the history
…cts (#409)
  • Loading branch information
RomainMuller authored Mar 28, 2019
1 parent 4cb91b3 commit 66789e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/jsii-kernel/lib/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/jsii-runtime/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ module.exports = {
use: ['source-map-loader'],
enforce: 'pre'
}]
},
optimization: {
minimize: false
}
}

0 comments on commit 66789e8

Please sign in to comment.