broccoli-6to5-transpiler
Advanced tools
14
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
var Filter = require('broccoli-filter'); | ||
var clone = require('clone'); | ||
@@ -22,14 +23,19 @@ function SixToFive(inputTree, options) { | ||
SixToFive.prototype.transform = function(string, options) { | ||
return transpiler.transform(string, options); | ||
}; | ||
SixToFive.prototype.processString = function (string, relativePath) { | ||
var opts = this.copyOptions(); | ||
var options = this.copyOptions(); | ||
opts.filename = opts.sourceMapName = opts.sourceFileName = relativePath; | ||
debugger; | ||
options.filename = options.sourceMapName = options.sourceFileName = relativePath; | ||
return transpiler.transform(string, opts).code; | ||
return this.transform(string, options).code; | ||
}; | ||
SixToFive.prototype.copyOptions = function() { | ||
return JSON.parse(JSON.stringify(this.options)); | ||
return clone(this.options); | ||
}; | ||
module.exports = SixToFive; |
{ | ||
"name": "broccoli-6to5-transpiler", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A Broccoli plugin which transpile ES6 to readable ES5 by using 6to5.", | ||
@@ -32,3 +32,4 @@ "main": "index.js", | ||
"6to5-core": "^2.11.0", | ||
"broccoli-filter": "^0.1.7" | ||
"broccoli-filter": "^0.1.7", | ||
"clone": "^0.2.0" | ||
}, | ||
@@ -35,0 +36,0 @@ "devDependencies": { |
62
test.js
@@ -12,6 +12,2 @@ 'use strict'; | ||
afterEach(function () { | ||
builder.cleanup(); | ||
}); | ||
function build(path, options) { | ||
@@ -23,3 +19,61 @@ builder = new broccoli.Builder(to5(path, options)); | ||
describe('options', function() { | ||
var options, toFive; | ||
before(function() { | ||
options = { | ||
foo: 1, | ||
bar: { | ||
baz: 1 | ||
} | ||
}; | ||
toFive = new to5('', options); | ||
}); | ||
it('are cloned', function() { | ||
var transpilerOptions; | ||
toFive.transform = function(string, options) { | ||
transpilerOptions = options; | ||
return { code: {} }; | ||
} | ||
expect(transpilerOptions).to.eql(undefined); | ||
toFive.processString('path', 'relativePath'); | ||
expect(transpilerOptions.foo).to.eql(1); | ||
expect(transpilerOptions.bar.baz).to.eql(1); | ||
options.foo = 2; | ||
options.bar.baz = 2; | ||
expect(transpilerOptions.foo).to.eql(1); | ||
expect(transpilerOptions.bar.baz).to.eql(1); | ||
}); | ||
it('correct fileName, sourceMapName, sourceFileName', function() { | ||
var transpilerOptions; | ||
toFive.transform = function(string, options) { | ||
transpilerOptions = options; | ||
return { code: {} }; | ||
} | ||
expect(transpilerOptions).to.eql(undefined); | ||
toFive.processString('path', 'relativePath'); | ||
expect(transpilerOptions.filename).to.eql('relativePath'); | ||
expect(transpilerOptions.sourceMapName).to.eql('relativePath'); | ||
expect(transpilerOptions.sourceFileName).to.eql('relativePath'); | ||
}); | ||
}) | ||
describe('transpile ES6 to ES5', function() { | ||
afterEach(function () { | ||
builder.cleanup(); | ||
}); | ||
it('basic', function () { | ||
@@ -26,0 +80,0 @@ return build(inputPath, {}).then(function(results) { |
6827
26.31%106
70.97%3
50%