From e85dd1647d0270114890659d86a570323ecb45f7 Mon Sep 17 00:00:00 2001 From: Charlie Greenman Date: Sat, 7 Oct 2023 21:02:31 -0400 Subject: [PATCH] add fix for stringified json --- .../add-property-to-html-tag/add-property-to-html-tag.spec.ts | 4 +--- .../add-property-to-html-tag/add-property-to-html-tag.ts | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.spec.ts b/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.spec.ts index 1161c3a..0d60ec9 100644 --- a/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.spec.ts +++ b/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.spec.ts @@ -6,9 +6,7 @@ describe('addPropertyToHtmlTag', () => { const fileToBeAddedTo = `
`; - const codeBlock = { - '(sideNavToggle)': 'sideNavToggle()' - }; + const codeBlock = '{"(sideNavToggle)": "sideNavToggle()"}'; const insertIntoHtmlTag: EditHtmlFile = { nodeType: 'addPropertyToHtmlTag', diff --git a/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.ts b/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.ts index 793bafe..417cb47 100644 --- a/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.ts +++ b/src/rz/angular/add-property-to-html-tag/add-property-to-html-tag.ts @@ -5,12 +5,13 @@ import { EditHtmlFile } from '../interfaces/edit-html.interface'; // will insert code into an html block export function addPropertyToHtmlTag(editFile: EditHtmlFile, fileToBeModified: any): any { + const codeBlock = typeof editFile.codeBlock === 'string' ? JSON.parse(editFile.codeBlock) : editFile.codeBlock; visit(fileToBeModified, { type: 'element', tagName: editFile.tagNameToInsertInto }, (node: any, index) => { // Check if the tag is the one you want to modify if (node.tagName === editFile.tagNameToInsertInto) { node.properties = { ...(node.properties || {}), - ...editFile.codeBlock + ...codeBlock }; } });