From b570b201d54f18230cffddd03b765bbc5643a58e Mon Sep 17 00:00:00 2001 From: Simon Stone Date: Wed, 15 Dec 2021 13:00:43 +0000 Subject: [PATCH] fix(*): set typescript enum values to strings (resolves #362) Signed-off-by: Simon Stone --- .../lib/codegen/fromcto/typescript/typescriptvisitor.js | 3 ++- .../test/codegen/fromcto/typescript/typescriptvisitor.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js index fcc8da5b2c..5b0f1b9e81 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -221,7 +221,8 @@ class TypescriptVisitor { * @private */ visitEnumValueDeclaration(enumValueDeclaration, parameters) { - parameters.fileWriter.writeLine(1, enumValueDeclaration.getName() + ','); + const name = enumValueDeclaration.getName(); + parameters.fileWriter.writeLine(1,`${name} = '${name}',`); return null; } diff --git a/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js b/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js index af339dafaf..376937841f 100644 --- a/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js @@ -443,7 +443,7 @@ describe('TypescriptVisitor', function () { }); describe('visitEnumValueDeclaration', () => { - it('should write a line with the name of the enum value', () => { + it('should write a line with the name and value of the enum value', () => { let param = { fileWriter: mockFileWriter }; @@ -454,7 +454,7 @@ describe('TypescriptVisitor', function () { typescriptVisitor.visitEnumValueDeclaration(mockEnumValueDeclaration, param); - param.fileWriter.writeLine.withArgs(1, 'Bob,').calledOnce.should.be.ok; + param.fileWriter.writeLine.withArgs(1, 'Bob = \'Bob\',').calledOnce.should.be.ok; }); });