diff --git a/client/src/templates/Challenges/rechallenge/transformers.js b/client/src/templates/Challenges/rechallenge/transformers.js index 76a448cff18..e4419e6db08 100644 --- a/client/src/templates/Challenges/rechallenge/transformers.js +++ b/client/src/templates/Challenges/rechallenge/transformers.js @@ -177,9 +177,17 @@ async function transformSASS(documentElement) { async function transformScript(documentElement) { await loadBabel(); await loadPresetEnv(); + await loadPresetReact(); const scriptTags = documentElement.querySelectorAll('script'); scriptTags.forEach(script => { - script.innerHTML = babelTransformCode(getBabelOptions(presetsJS))( + const isBabel = script.type === 'text/babel'; + // TODO: make the use of JSX conditional on more than just the script type. + // It should only be used for React challenges since it would be confusing + // for learners to see the results of a transformation they didn't ask for. + const options = isBabel ? presetsJSX : presetsJS; + + if (isBabel) script.removeAttribute('type'); // otherwise the browser will ignore the script + script.innerHTML = babelTransformCode(getBabelOptions(options))( script.innerHTML ); });