Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/compiler-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export default class CompilerHost {
*
* @private
*/
async compileUncached(filePath, hashInfo, compiler) {
async compileUncached(filePath, hashInfo, compiler, history=new Set()) {
let inputMimeType = mimeTypes.lookup(filePath);

if (hashInfo.isFileBinary) {
Expand All @@ -336,6 +336,7 @@ export default class CompilerHost {

let ctx = {};
let code = hashInfo.sourceCode || await pfs.readFile(filePath, 'utf8');
history.add(code);

if (!(await compiler.shouldCompileFile(code, ctx))) {
d(`Compiler returned false for shouldCompileFile: ${filePath}`);
Expand All @@ -359,6 +360,11 @@ export default class CompilerHost {
if ((finalForms[result.mimeType] && !shouldInlineHtmlify) || isPassthrough) {
// Got something we can use in-browser, let's return it
return Object.assign(result, {dependentFiles});
} else if (history.has(result.code)) {
d(`Compiler loop on ${filePath} after ${history.size - 1} prior candidates: assuming OK.`);
return Object.assign(result, {dependentFiles});
} else if (history.size > 30) {
throw new Error(`Compiling ${filePath} resulted in a recursive recompilation more than 30 levels deep: assuming broken.`);
} else {
d(`Recursively compiling result of ${filePath} with non-final MIME type ${result.mimeType}, input was ${inputMimeType}`);

Expand All @@ -373,7 +379,7 @@ export default class CompilerHost {

return await this.compileUncached(
`${filePath}.${mimeTypes.extension(result.mimeType || 'txt')}`,
hashInfo, compiler);
hashInfo, compiler, history);
}
}

Expand Down