Skip to content

Commit 9aed54d

Browse files
lorefnonplatinumazure
authored andcommitted
Fix incorrect behavior when arrow functions are used as default values (eslint#189)
1 parent 9efb6ca commit 9aed54d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Diff for: lib/doctrine.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@
523523
// extract the default value if there is one
524524
// example: @param {string} [somebody=John Doe] description
525525
assign = name.substring(1, name.length - 1).split('=');
526-
if (assign[1]) {
527-
this._tag['default'] = assign[1];
526+
if (assign.length > 1) {
527+
this._tag['default'] = assign.slice(1).join('=');
528528
}
529529
this._tag.name = assign[0];
530530

Diff for: test/parse.js

+22
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,28 @@ describe('optional params', function() {
22712271
});
22722272
});
22732273

2274+
it('default arrow functions', function() {
2275+
doctrine.parse(
2276+
["/**", " * @param {Function} [fn=()=>{}] some description", " */"].join('\n'),
2277+
{unwrap: true, sloppy: true}
2278+
).should.eql({
2279+
description: "",
2280+
tags: [{
2281+
"title": "param",
2282+
"description": "some description",
2283+
"type": {
2284+
"type": "OptionalType",
2285+
"expression": {
2286+
"type": "NameExpression",
2287+
"name": "Function"
2288+
}
2289+
},
2290+
"name": "fn",
2291+
"default": "()=>{}"
2292+
}]
2293+
});
2294+
});
2295+
22742296
it('line numbers', function() {
22752297
var res = doctrine.parse(
22762298
[

0 commit comments

Comments
 (0)