broccoli-babel-transpiler
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -14,2 +14,3 @@ 'use strict'; | ||
this.options = options || {}; | ||
this.extensions = this.options.filterExtensions || ['js']; | ||
} | ||
@@ -36,5 +37,9 @@ | ||
Babel.prototype.copyOptions = function() { | ||
return clone(this.options); | ||
var cloned = clone(this.options); | ||
if (cloned.filterExtensions) { | ||
delete cloned.filterExtensions; | ||
} | ||
return cloned; | ||
}; | ||
module.exports = Babel; |
{ | ||
"name": "broccoli-babel-transpiler", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "A Broccoli plugin which transpile ES6 to readable ES5 by using babel.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,1 +30,15 @@ # broccoli-babel-transpiler | ||
separate source map feature, welcome to submit a pull request. | ||
## Advanced usage | ||
`filterExtensions` is an option to limit (or expand) the set of file extensions that | ||
will be transformed. | ||
The default `filterExtension` is `js` | ||
```js | ||
var esTranspiler = require('broccoli-babel-transpiler'); | ||
var scriptTree = esTranspiler(inputTree, { | ||
filterExtensions:['js', 'es6'] // babelize both .js and .es6 files | ||
}); | ||
``` |
68
test.js
@@ -19,4 +19,2 @@ 'use strict'; | ||
describe('options', function() { | ||
var options, babel; | ||
@@ -29,6 +27,7 @@ | ||
baz: 1 | ||
} | ||
}, | ||
filterExtensions: ['es6'] | ||
}; | ||
babel = new Babel('', options); | ||
babel = new Babel('', options); | ||
}); | ||
@@ -72,4 +71,17 @@ | ||
}); | ||
}) | ||
it('does not propogate validExtensions', function () { | ||
var transpilerOptions; | ||
babel.transform = function(string, options) { | ||
transpilerOptions = options; | ||
return { code: {} }; | ||
}; | ||
expect(transpilerOptions).to.eql(undefined); | ||
babel.processString('path', 'relativePath'); | ||
expect(transpilerOptions.filterExtensions).to.eql(undefined); | ||
}); | ||
}); | ||
describe('transpile ES6 to ES5', function() { | ||
@@ -81,3 +93,6 @@ afterEach(function () { | ||
it('basic', function () { | ||
return build(inputPath, {}).then(function(results) { | ||
return build(inputPath, { | ||
inputSourceMap:false, | ||
sourceMap: false | ||
}).then(function(results) { | ||
var outputPath = results.directory; | ||
@@ -105,1 +120,42 @@ | ||
}); | ||
describe('filters files to transform', function() { | ||
afterEach(function () { | ||
builder.cleanup(); | ||
}); | ||
it('default', function () { | ||
return build(inputPath, { | ||
inputSourceMap:false, | ||
sourceMap: false | ||
}).then(function(results) { | ||
var outputPath = results.directory; | ||
var output = fs.readFileSync(path.join(outputPath, 'fixtures.js')).toString(); | ||
var input = fs.readFileSync(path.join(inputPath, 'expected.js')).toString(); | ||
expect(output).to.eql(input); | ||
// Verify that .es6 file was not transformed | ||
expect(fs.existsSync(path.join(outputPath, 'fixtures-es6.es6'))).to.be.ok; | ||
}); | ||
}); | ||
it('uses specified filter', function () { | ||
return build(inputPath, { | ||
filterExtensions: ['es6'], | ||
inputSourceMap:false, | ||
sourceMap: false | ||
}).then(function(results) { | ||
var outputPath = results.directory; | ||
var output = fs.readFileSync(path.join(outputPath, 'fixtures-es6.js')).toString(); | ||
var input = fs.readFileSync(path.join(inputPath, 'expected.js')).toString(); | ||
expect(output).to.eql(input); | ||
// Verify that .es6 file was not transformed | ||
expect(fs.existsSync(path.join(outputPath, 'fixtures-es6.es6'))).to.not.be.ok; | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9018
11
156
44
0