From 28241cd1b2eaa61818ec7fb1b4dd298c5452566a Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Thu, 6 Jun 2019 10:29:27 +0300 Subject: [PATCH] fix(jsii-diff): crash when changing method to a property (#521) Famous last words: "Trust me I know what I'm doing" Fixes #520 --- packages/jsii-diff/lib/classes-ifaces.ts | 16 ++++--- packages/jsii-diff/test/test.classes.ts | 56 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/packages/jsii-diff/lib/classes-ifaces.ts b/packages/jsii-diff/lib/classes-ifaces.ts index f2f0ace0fc..5f7ef5e694 100644 --- a/packages/jsii-diff/lib/classes-ifaces.ts +++ b/packages/jsii-diff/lib/classes-ifaces.ts @@ -27,12 +27,16 @@ export function compareReferenceType(original: context.mismatches.report(original, 'has gone from @subclassable to non-@subclassable'); } - for (const [origMethod, updatedMethod] of memberPairs(original, original.allMethods, updated, context)) { - compareMethod(original, origMethod, updatedMethod, context); + for (const [origMethod, updatedElement] of memberPairs(original, original.allMethods, updated, context)) { + if (reflect.isMethod(origMethod) && reflect.isMethod(updatedElement)) { + compareMethod(original, origMethod, updatedElement, context); + } } - for (const [origProp, updatedProp] of memberPairs(original, original.allProperties, updated, context)) { - compareProperty(original, origProp, updatedProp, context); + for (const [origProp, updatedElement] of memberPairs(original, original.allProperties, updated, context)) { + if (reflect.isProperty(origProp) && reflect.isProperty(updatedElement)) { + compareProperty(original, origProp, updatedElement, context); + } } // You cannot have added abstract members to the class/interface, as they are @@ -174,7 +178,7 @@ function compareProperty(origClass: reflect.Type, original: reflect.Property, up } // tslint:disable-next-line:max-line-length -function* memberPairs(origClass: U, xs: T[], updatedClass: U, context: ComparisonContext): IterableIterator<[T, T]> { +function* memberPairs(origClass: U, xs: T[], updatedClass: U, context: ComparisonContext): IterableIterator<[T, reflect.TypeMember]> { for (const origMember of xs.filter(shouldInspect(context))) { LOG.trace(`${origClass.fqn}#${origMember.name}`); @@ -192,7 +196,7 @@ function* memberPairs