diff --git a/src/compiler-host.js b/src/compiler-host.js index 00cff54..dedd1ad 100644 --- a/src/compiler-host.js +++ b/src/compiler-host.js @@ -26,6 +26,8 @@ const finalForms = { 'application/json': true }; +const mimeTypesToPassthrough = ['text/plain', 'application/xml']; + /** * This class is the top-level class that encapsulates all of the logic of * compiling and caching application code. If you're looking for a "Main class", @@ -342,12 +344,8 @@ export default class CompilerHost { inputMimeType !== 'text/html' && result.mimeType === 'text/html'; - let isPassthrough = - result.mimeType === 'text/plain' || - !result.mimeType || - CompilerHost.shouldPassthrough(hashInfo); - if ((finalForms[result.mimeType] && !shouldInlineHtmlify) || isPassthrough) { + if ((finalForms[result.mimeType] && !shouldInlineHtmlify) || _isPassthrough(result, hashInfo)) { // Got something we can use in-browser, let's return it return Object.assign(result, {dependentFiles}); } else { @@ -575,12 +573,7 @@ export default class CompilerHost { inputMimeType !== 'text/html' && result.mimeType === 'text/html'; - let isPassthrough = - result.mimeType === 'text/plain' || - !result.mimeType || - CompilerHost.shouldPassthrough(hashInfo); - - if ((finalForms[result.mimeType] && !shouldInlineHtmlify) || isPassthrough) { + if ((finalForms[result.mimeType] && !shouldInlineHtmlify) || _isPassthrough(result, hashInfo)) { // Got something we can use in-browser, let's return it return Object.assign(result, {dependentFiles}); } else { @@ -691,3 +684,16 @@ export default class CompilerHost { return sourceCode; } } + +// Private helper functions +// (to help DRY up CompilerHost methods with shared code such as compileUncached & compileUncachedSync) + +function _isPassthrough(result, hashInfo) { + return _shouldIgnoreMimeType(result.mimeType) || + CompilerHost.shouldPassthrough(hashInfo); +} + +function _shouldIgnoreMimeType(mimeType) { + return mimeTypesToPassthrough.indexOf(mimeType) !== -1 || + !mimeType; +}