Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kernel): Transitively consider properties when deserializing structs #409

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}