Skip to content

Commit

Permalink
Merge pull request #128 from 2Pacalypse-/master
Browse files Browse the repository at this point in the history
Add support for object spread/rest operator.
  • Loading branch information
jhnns authored Apr 9, 2018
2 parents 18c5d0e + 122689e commit d9a81c0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/moduleEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ function jsExtension(module, filename) {

module._compile = function (content, filename) {
content = babelCore.transform(content, {
plugins: [require.resolve("babel-plugin-transform-es2015-block-scoping")],
plugins: [
require.resolve("babel-plugin-transform-es2015-block-scoping"),
require.resolve("babel-plugin-transform-object-rest-spread")
],
retainLines: true,
filename: filename,
babelrc: false
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"babel-core": "^6.26.0",
"babel-plugin-transform-es2015-block-scoping": "^6.26.0"
"babel-plugin-transform-es2015-block-scoping": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0"
}
}
2 changes: 2 additions & 0 deletions testLib/objectRestOperator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let { ...a } = {};
module.exports = a;
1 change: 1 addition & 0 deletions testLib/objectSpreadOperator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { ...{} };
12 changes: 12 additions & 0 deletions testLib/sharedTestCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ module.exports = function () {
}).to.not.throwException();
});

it("should not be a problem to have a module that uses object spread operator", function() {
expect(function() {
var rewired = rewire("./objectSpreadOperator.js");
}).to.not.throwException();
});

it("should not be a problem to have a module that uses object rest operator", function() {
expect(function() {
var rewired = rewire("./objectRestOperator.js");
}).to.not.throwException();
});

it("should not influence the original require if nothing has been required within the rewired module", function () {
rewire("./emptyModule.js"); // nothing happens here because emptyModule doesn't require anything
expect(require("./moduleA.js").__set__).to.be(undefined); // if restoring the original node require didn't worked, the module would have a setter
Expand Down

0 comments on commit d9a81c0

Please sign in to comment.