Skip to content

Commit

Permalink
add fix for stringified json
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieGreenman committed Oct 8, 2023
1 parent ae4376b commit e85dd16
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ describe('addPropertyToHtmlTag', () => {
const fileToBeAddedTo = `<div>
<devgen-eureka-seven-global-header> </devgen-eureka-seven-global-header>
</div>`;
const codeBlock = {
'(sideNavToggle)': 'sideNavToggle()'
};
const codeBlock = '{"(sideNavToggle)": "sideNavToggle()"}';

const insertIntoHtmlTag: EditHtmlFile = {
nodeType: 'addPropertyToHtmlTag',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
});
Expand Down

0 comments on commit e85dd16

Please sign in to comment.