Skip to content

Commit

Permalink
Support source maps in direct transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Feb 17, 2015
1 parent 91c28dd commit 1a2449c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/parser.js
Expand Up @@ -153,13 +153,20 @@ readFileContent = function (code, filename, parser, localFilename) {
type = ext;
sourceUrl = localFilename;
if (parser.transform) {
code = deferred(parser.transform(filename, code))(function (code) {
if (code == null) {
code = deferred(parser.transform(filename, code))(function (data) {
var code;
if (data == null) {
throw customError("Provided transform callback must return code string",
'INVALID_TRANSFORM');
}
if (ext !== '.js') return String(code);
return stripBOM(String(code)).replace(sheBangRe, '//$1\n');
code = data.code || data;
if (ext !== '.js') code = String(code);
else code = stripBOM(String(code)).replace(sheBangRe, '//$1\n');
if (parser.sourceMap && data.sourceMap) {
code += '//# sourceMappingURL=data:application/json;base64,' +
new Buffer(data.sourceMap).toString('base64') + '\n';
}
return code;
});
} else if (ext === '.js') {
code = stripBOM(code).replace(sheBangRe, '//$1\n');
Expand Down

0 comments on commit 1a2449c

Please sign in to comment.