fix(client): stop injecting extra comments into preview (#44723)

This commit is contained in:
Oliver Eyton-Williams
2022-01-13 22:25:55 +01:00
committed by GitHub
parent e97920ae9c
commit a00788417a
2 changed files with 8 additions and 18 deletions

View File

@ -14,36 +14,28 @@ import {
transformContents transformContents
} from '../../../../../utils/polyvinyl'; } from '../../../../../utils/polyvinyl';
const htmlCatch = '\n<!--fcc-->\n';
const jsCatch = '\n;/*fcc*/\n';
const cssCatch = '\n/*fcc*/\n';
const defaultTemplate = ({ source }) => { const defaultTemplate = ({ source }) => {
return ` return `
<body id='display-body'> <body id='display-body'>
<!-- fcc-start-source --> ${source}
${source}
<!-- fcc-end-source -->
</body>`; </body>`;
}; };
const wrapInScript = partial( const wrapInScript = partial(
transformContents, transformContents,
content => `${htmlCatch}<script>${content}${jsCatch}</script>` content => `<script>${content}</script>`
); );
const wrapInStyle = partial( const wrapInStyle = partial(
transformContents, transformContents,
content => `${htmlCatch}<style>${content}${cssCatch}</style>` content => `<style>${content}</style>`
); );
const setExtToHTML = partial(setExt, 'html'); const setExtToHTML = partial(setExt, 'html');
const padContentWithJsCatch = partial(compileHeadTail, jsCatch); const concatHeadTail = partial(compileHeadTail, '');
const padContentWithCssCatch = partial(compileHeadTail, cssCatch);
// const padContentWithHTMLCatch = partial(compileHeadTail, htmlCatch);
export const jsToHtml = cond([ export const jsToHtml = cond([
[ [
matchesProperty('ext', 'js'), matchesProperty('ext', 'js'),
flow(padContentWithJsCatch, wrapInScript, setExtToHTML) flow(concatHeadTail, wrapInScript, setExtToHTML)
], ],
[stubTrue, identity] [stubTrue, identity]
]); ]);
@ -51,7 +43,7 @@ export const jsToHtml = cond([
export const cssToHtml = cond([ export const cssToHtml = cond([
[ [
matchesProperty('ext', 'css'), matchesProperty('ext', 'css'),
flow(padContentWithCssCatch, wrapInStyle, setExtToHTML) flow(concatHeadTail, wrapInStyle, setExtToHTML)
], ],
[stubTrue, identity] [stubTrue, identity]
]); ]);
@ -96,12 +88,12 @@ A required file can not have both a src and a link: src = ${src}, link = ${link}
const indexHtml = findIndexHtml(challengeFiles); const indexHtml = findIndexHtml(challengeFiles);
const source = challengeFiles.reduce((source, challengeFile) => { const source = challengeFiles.reduce((source, challengeFile) => {
if (!indexHtml) return source.concat(challengeFile.contents, htmlCatch); if (!indexHtml) return source.concat(challengeFile.contents);
if ( if (
indexHtml.importedFiles.includes(challengeFile.history[0]) || indexHtml.importedFiles.includes(challengeFile.history[0]) ||
wasHtmlFile(challengeFile) wasHtmlFile(challengeFile)
) { ) {
return source.concat(challengeFile.contents, htmlCatch); return source.concat(challengeFile.contents);
} else { } else {
return source; return source;
} }

View File

@ -105,8 +105,6 @@ async function loadPresetReact() {
const babelTransformCode = options => code => const babelTransformCode = options => code =>
Babel.transform(code, options).code; Babel.transform(code, options).code;
// const sourceReg =
// /(<!-- fcc-start-source -->)([\s\S]*?)(?=<!-- fcc-end-source -->)/g;
const NBSPReg = new RegExp(String.fromCharCode(160), 'g'); const NBSPReg = new RegExp(String.fromCharCode(160), 'g');
const testJS = matchesProperty('ext', 'js'); const testJS = matchesProperty('ext', 'js');