Skip to content
This repository was archived by the owner on Feb 8, 2020. It is now read-only.

Commit 6e3edbe

Browse files
fix(): Fix issue #120
Default values are now returned as strings instead of raw values when parameter default value consists of a list of expressions. This is the expected behavior a the lib. Plus, the fix is now much cleaner. TAG: latest fixes #120
1 parent d4996d5 commit 6e3edbe

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/lib/plugins/params.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ export default (app) => (node, result) => {
3434
result.args.push(name)
3535

3636
if (param.right && param.right.type === 'SequenceExpression') {
37-
let value
3837
let lastExpression = param.right.expressions.pop()
3938

40-
if (lastExpression.type === 'NullLiteral') {
41-
value = null
42-
} else {
43-
value = lastExpression.value
44-
}
45-
46-
result.defaults[name] = value
39+
result.defaults[name] = result.value.slice(
40+
lastExpression.start,
41+
lastExpression.end
42+
)
4743
} else {
4844
result.defaults[name] = param.right
4945
? result.value.slice(param.right.start, param.right.end)

test/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const actuals = {
3131
'function () {}',
3232
'function (a = (true, false)) {}',
3333
'function (a = (true, null)) {}',
34+
'function (a = (true, "bar")) {}',
3435
'function (a, b = (i++, true)) {}',
3536
],
3637
named: [
@@ -41,6 +42,7 @@ const actuals = {
4142
'function namedFn () {}',
4243
'function namedFn(a = (true, false)) {}',
4344
'function namedFn(a = (true, null)) {}',
45+
'function namedFn(a = (true, "bar")) {}',
4446
'function namedFn(a, b = (i++, true)) {}',
4547
],
4648
generators: [
@@ -51,6 +53,7 @@ const actuals = {
5153
'function * namedFn () {}',
5254
'function * namedFn(a = (true, false)) {}',
5355
'function * namedFn(a = (true, null)) {}',
56+
'function * namedFn(a = (true, "bar")) {}',
5457
'function * namedFn(a, b = (i++, true)) {}',
5558
],
5659
arrows: [
@@ -61,6 +64,7 @@ const actuals = {
6164
'() => {}',
6265
'(a = (true, false)) => {}',
6366
'(a = (true, null)) => {}',
67+
'(a = (true, "bar")) => {}',
6468
'(a, b = (i++, true)) => {}',
6569
'(a) => a * 3 * a',
6670
'd => d * 355 * d',
@@ -126,21 +130,28 @@ const regulars = [
126130
params: 'a',
127131
args: ['a'],
128132
body: '',
129-
defaults: {a: false},
133+
defaults: {a: 'false'},
130134
},
131135
{
132136
name: null,
133137
params: 'a',
134138
args: ['a'],
135139
body: '',
136-
defaults: {a: null},
140+
defaults: {a: 'null'},
141+
},
142+
{
143+
name: null,
144+
params: 'a',
145+
args: ['a'],
146+
body: '',
147+
defaults: {a: '"bar"'},
137148
},
138149
{
139150
name: null,
140151
params: 'a, b',
141152
args: ['a', 'b'],
142153
body: '',
143-
defaults: {a: undefined, b: true},
154+
defaults: {a: undefined, b: 'true'},
144155
},
145156
]
146157

0 commit comments

Comments
 (0)