Implement ResourceSlot#_addDirectlyToJsOutputResources to fix #10337. (#10338)

This commit is contained in:
Ben Newman
2018-11-15 11:10:47 -06:00
committed by Ben Newman
parent c06a31a322
commit 5e7e809cd1

View File

@@ -571,19 +571,7 @@ class ResourceSlot {
// If we have a sourceProcessor, it will handle the adding of the
// final processed JavaScript.
} else if (self.inputResource.extension === "js") {
// If there is no sourceProcessor for a .js file, add the source
// directly to the output. #HardcodeJs
self.addJavaScript({
// XXX it's a shame to keep converting between Buffer and string, but
// files.convertToStandardLineEndings only works on strings for now
data: self.inputResource.data.toString('utf8'),
path: self.inputResource.path,
bare: self.inputResource.fileOptions &&
(self.inputResource.fileOptions.bare ||
// XXX eventually get rid of backward-compatibility "raw" name
// XXX COMPAT WITH 0.6.4
self.inputResource.fileOptions.raw)
});
self._addDirectlyToJsOutputResources();
}
} else {
if (sourceProcessor) {
@@ -593,16 +581,23 @@ class ResourceSlot {
// Any resource that isn't handled by compiler plugins just gets passed
// through.
if (self.inputResource.type === "js") {
self.jsOutputResources.push(new JsOutputResource({
resourceSlot: self,
options: self.inputResource,
}));
self._addDirectlyToJsOutputResources();
} else {
self.outputResources.push(self.inputResource);
}
}
}
// Add this resource directly to jsOutputResources without modifying the
// original data. #HardcodeJs
_addDirectlyToJsOutputResources() {
this.addJavaScript({
...(this.inputResource.fileOptions || {}),
path: this.inputResource.path,
data: this.inputResource.data,
});
}
_getOption(name, options) {
if (options && _.has(options, name)) {
return options[name];
@@ -693,6 +688,15 @@ class ResourceSlot {
return isInImports;
}
_isBare(options) {
return !! (
this._getOption("bare", options) ||
// XXX eventually get rid of backwards-compatible "raw" name
// XXX COMPAT WITH 0.6.4
this._getOption("raw", options)
);
}
addStylesheet(options, lazyFinalizer) {
if (! this.sourceProcessor) {
throw Error("addStylesheet on non-source ResourceSlot?");
@@ -868,7 +872,7 @@ class OutputResource {
Object.assign(this, {
type,
lazy: resourceSlot._isLazy(options, true),
bare: !! resourceSlot._getOption("bare", options),
bare: resourceSlot._isBare(options),
mainModule: !! resourceSlot._getOption("mainModule", options),
sourcePath,
targetPath,