Skip to content

Commit

Permalink
Define list of MIME types to passthrough (for electron-userland#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobq committed Mar 3, 2017
1 parent 146995c commit bf964b1
Showing 1 changed file with 17 additions and 11 deletions.
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;
}

0 comments on commit bf964b1

Please sign in to comment.