From bf964b1b9237bd6ec5f16bb0743c631e3af6b0c4 Mon Sep 17 00:00:00 2001 From: Jacob Quant Date: Fri, 3 Mar 2017 10:31:34 -0600 Subject: [PATCH] Define list of MIME types to passthrough (for #167) --- src/compiler-host.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) 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; +}