mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-17 22:01:24 -04:00
feat: transform JSX in scripts (#55860)
This commit is contained in:
committed by
GitHub
parent
2386c57edb
commit
23888d618a
@@ -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
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user