Skip to content

Commit

Permalink
avoid potentially slow regex call in renderJsx
Browse files Browse the repository at this point in the history
  • Loading branch information
maerten committed Jul 14, 2021
1 parent dc390b8 commit f001b11
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions addons/docs/src/frameworks/react/jsxDecorator.tsx
Expand Up @@ -115,12 +115,14 @@ export const renderJsx = (code: React.ReactElement, options: JSXOptions) => {
// @ts-ignore FIXME: workaround react-element-to-jsx-string
const child = typeof c === 'number' ? c.toString() : c;
let string = applyBeforeRender(reactElementToJSXString(child, opts as Options), options);
const matches = string.match(/\S+=\\"([^"]*)\\"/g);

if (matches) {
matches.forEach((match) => {
string = string.replace(match, match.replace(/"/g, "'"));
});
if (string.indexOf('"') > -1) {
const matches = string.match(/\S+=\\"([^"]*)\\"/g);
if (matches) {
matches.forEach((match) => {
string = string.replace(match, match.replace(/"/g, "'"));
});
}
}

return string;
Expand Down

0 comments on commit f001b11

Please sign in to comment.