6to5-brunch
Advanced tools
Comparing version 1.7.2 to 1.7.3
25
index.js
@@ -0,5 +1,7 @@ | ||
'use strict'; | ||
var to5 = require('6to5'); | ||
function ES6to5Compiler(config) { | ||
if (config == null) config = {}; | ||
if (config == null) { config = {}; } | ||
var options = config.plugins && config.plugins.ES6to5 || {}; | ||
@@ -9,6 +11,6 @@ var _this = this; | ||
Object.keys(options).forEach(function (key) { | ||
if (key === 'sourceMap') return; | ||
if (key === 'sourceMap') { return; } | ||
_this.options[key] = options[key]; | ||
}); | ||
this.options.sourceMapObject = !!config.sourceMaps; | ||
this.options.sourceMaps = !!config.sourceMaps; | ||
} | ||
@@ -22,3 +24,3 @@ | ||
this.options.filename = params.path; | ||
var compiled, lines, mapComment, map; | ||
var compiled; | ||
try { | ||
@@ -29,15 +31,8 @@ compiled = to5.transform(params.data, this.options); | ||
} | ||
if (this.options.sourceMap) { | ||
lines = compiled.code.split('\n'); | ||
mapComment = lines.splice(-2, 1)[0]; | ||
if (mapComment.slice(0, 26) === '//# sourceMappingURL=data:') { | ||
compiled = lines.join('\n'); | ||
map = (new Buffer(mapComment.slice(50), 'base64').toString()); | ||
} | ||
} else { | ||
compiled = {code: compiled}; | ||
} | ||
return callback(null, {data: compiled.code, map: compiled.map}); | ||
callback(null, { | ||
data: compiled.code || compiled, | ||
map: !!compiled.map && compiled.map.toJSON() | ||
}); | ||
}; | ||
module.exports = ES6to5Compiler; |
{ | ||
"name": "6to5-brunch", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"description": "Brunch plugin to turn ES6 code into vanilla ES5 with no runtime required.", | ||
@@ -5,0 +5,0 @@ "author": "Elan Shanker", |
@@ -1,2 +0,3 @@ | ||
# 6to5-brunch | ||
6to5-brunch | ||
=========== | ||
Brunch plugin using [6to5](https://github.com/sebmck/6to5) to turn ES6 code | ||
@@ -7,6 +8,8 @@ into vanilla ES5 with no runtime required. | ||
## Installation | ||
Installation | ||
------------ | ||
`npm install --save 6to5-brunch` | ||
## Configuration | ||
Configuration | ||
------------- | ||
Set [6to5 options](https://github.com/sebmck/6to5#options) in your brunch | ||
@@ -24,4 +27,8 @@ config (such as `brunch-config.coffee`) exceptfor `filename` and `sourceMap` | ||
## License | ||
Change Log | ||
---------- | ||
[See release notes page on GitHub](https://github.com/es128/6to5-brunch/releases) | ||
License | ||
------- | ||
[ISC](https://raw.github.com/es128/6to5-brunch/master/LICENSE) |
33
3079
30