Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Support raw of loaders #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lib/applyLoaders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var HappyFakeLoaderContext = require('./HappyFakeLoaderContext');
var fnOncePedantic = require('./fnOncePedantic');
var convertArgs = require('./convertArgs');
var assert = require('assert');

/**
Expand Down Expand Up @@ -274,7 +275,11 @@ function NormalLoaderApplier(loaders, dataMap, done) {
loader.module
;

applySyncOrAsync(fn, context, [ sourceCode, sourceMap ],
var raw = loader.module.raw;

var args = [ sourceCode, sourceMap ];

applySyncOrAsync(fn, context, convertArgs(args, raw),
function(err, nextSource, nextSourceMap) {
if (err) {
return done(err);
Expand Down
24 changes: 24 additions & 0 deletions lib/convertArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = function convertArgs(args, raw) {
/* Not sure why buffer would convert to JSON */
if (args[0].type === 'Buffer') {
args[0] = Buffer.from(args[0].data);
}

if(!raw && Buffer.isBuffer(args[0])) {
args[0] = utf8BufferToString(args[0]);
}
else if(raw && typeof args[0] === "string") {
args[0] = new Buffer(args[0], "utf-8");
}

return args;
}

function utf8BufferToString(buf) {
var str = buf.toString("utf-8");
if(str.charCodeAt(0) === 0xFEFF) {
return str.substr(1);
} else {
return str;
}
}