Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Add ES6 arrow function support to utils.clean

Nick Fitzgerald4e92dc684e89
diff --git a/lib/utils.js b/lib/utils.js
index 37fd5d7e..fee835ba 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -209,7 +209,7 @@ exports.slug = function(str){
exports.clean = function(str) {
str = str
.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
- .replace(/^function *\(.*\) *{/, '')
+ .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '')
.replace(/\s+\}$/, '');
var spaces = str.match(/^\n?( *)/)[1].length
diff --git a/test/acceptance/utils.js b/test/acceptance/utils.js
index 97373687..cc494250 100644
--- a/test/acceptance/utils.js
+++ b/test/acceptance/utils.js
@@ -55,5 +55,19 @@ describe('lib/utils', function () {
].join("\r\n");
utils.clean(fn).should.equal("if (false) {\n\tvar json = {\n\t\tone : 1\n\t};\n}");
});
+
+ it("should format es6 arrow functions", function () {
+ var fn = [
+ "() => {",
+ " var a = 1;",
+ "}"
+ ].join("\n");
+ utils.clean(fn).should.equal("var a = 1;");
+ });
+
+ it("should format es6 arrow functions with implicit return", function () {
+ var fn = "() => foo()";
+ utils.clean(fn).should.equal("foo()");
+ });
});
});
\ No newline at end of file