From 65948f6a249daf6daab023d640b601b9961c796d Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Wed, 31 May 2023 19:02:02 -0400 Subject: [PATCH] fix: generated examples fail when scope is not of type Construct --- src/generate.ts | 6 +++++- test/generate.test.ts | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/generate.ts b/src/generate.ts index 720b04d2..7cfa364d 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -175,7 +175,11 @@ function generateStaticFactoryPropertyExample(staticFactoryProperty: reflect.Pro * Generate an example value of the given parameter. */ function exampleValueForParameter(context: ExampleContext, param: reflect.Parameter, position: number, level: number): Code { - if (param.name === 'scope' && position === 0) { + if ( + param.name === 'scope' && + ['constructs.IConstruct', 'constructs.Construct'].includes(param.type.fqn ?? '') && + position === 0 + ) { return new Code('this'); } diff --git a/test/generate.test.ts b/test/generate.test.ts index 5e9e791d..fbf98761 100644 --- a/test/generate.test.ts +++ b/test/generate.test.ts @@ -93,7 +93,7 @@ describe('generateClassAssignment ', () => { 'declare const prop5: any;', 'declare const property: my_assembly.Property;', '', - 'const classA = new my_assembly.ClassA(this, \'MyClassA\', {', + 'const classA = new my_assembly.ClassA(\'scope\', \'MyClassA\', {', ' prop1: 123,', ' prop2: property,', ' prop3: [\'prop3\'],', @@ -150,7 +150,7 @@ describe('generateClassAssignment ', () => { expected: [ 'import * as my_assembly from \'my_assembly\';', '', - 'const classA = new my_assembly.ClassA(this, \'MyClassA\', {', + 'const classA = new my_assembly.ClassA(\'scope\', \'MyClassA\', {', ' prop1: 123,', '', ' // the properties below are optional', @@ -178,7 +178,7 @@ describe('generateClassAssignment ', () => { expected: [ 'import * as my_assembly from \'my_assembly\';', '', - 'const classA = new my_assembly.ClassA(this, \'MyClassA\', /* all optional props */ {', + 'const classA = new my_assembly.ClassA(\'scope\', \'MyClassA\', /* all optional props */ {', ' prop1: 123,', ' prop2: 123,', '});',