Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Define list of MIME types to passthrough (for #167) #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 17 additions & 11 deletions src/compiler-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}