diff --git a/packages/analyzer/src/javascript/esutil.ts b/packages/analyzer/src/javascript/esutil.ts index 463b5e244..090ac1ab5 100644 --- a/packages/analyzer/src/javascript/esutil.ts +++ b/packages/analyzer/src/javascript/esutil.ts @@ -409,7 +409,7 @@ export function toMethodParam( } else if ( babel.isAssignmentPattern(nodeParam) && - babel.isIdentifier(nodeParam.left) && babel.isLiteral(nodeParam.right)) { + babel.isIdentifier(nodeParam.left)) { // Parameter with a default: method(param = "default") name = nodeParam.left.name; defaultValue = generate(nodeParam.right).code; diff --git a/packages/analyzer/src/test/javascript/class-scanner_test.ts b/packages/analyzer/src/test/javascript/class-scanner_test.ts index 24d81e27a..a98df8691 100644 --- a/packages/analyzer/src/test/javascript/class-scanner_test.ts +++ b/packages/analyzer/src/test/javascript/class-scanner_test.ts @@ -250,6 +250,17 @@ suite('Class', async () => { name: 'customInstanceFunction', description: '', }, + { + name: 'methodWithDefaultParam', + description: '', + params: [{name: 'x', defaultValue: '12'}], + }, + { + name: 'methodWithComplexDefaultParam', + description: '', + params: [{name: 'a', defaultValue: '[1, 2, 3]'}], + return: { type: 'void' } + }, { name: 'customInstanceFunctionWithJSDoc', description: 'This is the description for ' + @@ -514,6 +525,17 @@ suite('Class', async () => { name: 'customInstanceFunction', description: '', }, + { + name: 'methodWithDefaultParam', + description: '', + params: [{name: 'x', defaultValue: '12'}], + }, + { + name: 'methodWithComplexDefaultParam', + description: '', + params: [{name: 'a', defaultValue: '[1, 2, 3]'}], + return: { type: 'void' } + }, { name: 'customInstanceFunctionWithJSDoc', description: 'This is the description for ' + @@ -527,7 +549,6 @@ suite('Class', async () => { name: 'customInstanceFunctionWithParams', description: '', params: [{name: 'a'}, {name: 'b'}, {name: 'c'}], - }, { name: 'customInstanceFunctionWithParamsAndJSDoc', diff --git a/packages/analyzer/src/test/static/class/class-methods.js b/packages/analyzer/src/test/static/class/class-methods.js index 07b50b5f4..4d3087c59 100644 --- a/packages/analyzer/src/test/static/class/class-methods.js +++ b/packages/analyzer/src/test/static/class/class-methods.js @@ -15,6 +15,14 @@ class Class { return 4; } + methodWithDefaultParam(x = 12) { + return 24; + } + + methodWithComplexDefaultParam(a = [1, 2, 3]) { + return; + } + /** * This is the description for customInstanceFunctionWithJSDoc. * @return {Number} - The number 5, always.