From cc99c1eb0616a618276dec0fd1ebe7c51e45a7de Mon Sep 17 00:00:00 2001 From: Ryuichi Okumura Date: Sat, 8 Nov 2014 22:35:25 +0900 Subject: [PATCH] Fix fails to parse a default param value that contains a space It changes to accept a spaces in optional params. This fixes #268. --- lib/docparser.js | 2 +- tests/input/test/test.js | 3 ++- tests/parser.js | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/docparser.js b/lib/docparser.js index 2f966e9d..cbac22a6 100644 --- a/lib/docparser.js +++ b/lib/docparser.js @@ -63,7 +63,7 @@ YUI.add('docparser', function (Y) { CURRENT_CLASS = 'currentclass', REGEX_TYPE = /(.*?)\{(.*?)\}(.*)/, - REGEX_FIRSTWORD = /^\s*?([^\s]+)(.*)/, + REGEX_FIRSTWORD = /^\s*?(\[.+\]\*?|[^\s]+)(.*)/, REGEX_OPTIONAL = /^\[(.*)\]$/, REGEX_START_COMMENT = { js: /^\s*\/\*\*/, diff --git a/tests/input/test/test.js b/tests/input/test/test.js index c373d048..f9cce535 100644 --- a/tests/input/test/test.js +++ b/tests/input/test/test.js @@ -42,7 +42,8 @@ * @param {int} namesecond my desc * @param namefirst {string} my desc * @param [optionalvar] {bool} my desc - * @param {string} [optionalwithdefault="defaultval"] my desc + * @param {string} [optionalDefault1="defaultVal"] my desc + * @param {string} [optionalDefault2="defaultVal1 defaultVal2"] my desc * @evil * @injects {HTML} uses a string parameter to populate innerHTML * @returns something without a type diff --git a/tests/parser.js b/tests/parser.js index f30a0c10..db5a0ef3 100644 --- a/tests/parser.js +++ b/tests/parser.js @@ -263,7 +263,7 @@ suite.add(new YUITest.TestCase({ var item, item2, item3, item4; item = this.findByName('testoptional', 'myclass'); Assert.isArray(item.params, 'Params should be an array'); - Assert.areSame(5, item.params.length, 'Failed to parse all 5 parameters'); + Assert.areSame(6, item.params.length, 'Failed to parse all 6 parameters'); Assert.areSame('notype', item.params[0].name, 'Name missing'); Assert.isUndefined(item.params[0].type, 'Type should be missing'); @@ -275,10 +275,13 @@ suite.add(new YUITest.TestCase({ Assert.isTrue(item.params[3].optional, 'Parameter should be optional'); Assert.isUndefined(item.params[3].optdefault, 'Optional Default value should be undefined'); - - Assert.areSame('optionalwithdefault', item.params[4].name, 'Name missing'); + Assert.areSame('optionalDefault1', item.params[4].name, 'Name missing'); Assert.isTrue(item.params[4].optional, 'Parameter should be optional'); - Assert.areSame('"defaultval"', item.params[4].optdefault, 'Optional Default value is incorrect'); + Assert.areSame('"defaultVal"', item.params[4].optdefault, 'Optional Default value is incorrect'); + + Assert.areSame('optionalDefault2', item.params[5].name, 'Name missing'); + Assert.isTrue(item.params[5].optional, 'Parameter should be optional'); + Assert.areSame('"defaultVal1 defaultVal2"', item.params[5].optdefault, 'Optional Default value is incorrect'); item2 = this.findByName('test0ton', 'myclass'); Assert.isArray(item2.params, 'Params should be an array');