Skip to content

Commit cd8f084

Browse files
authored
Merge pull request #65 from heavenshell/fix/default_params
Fix/default params
2 parents 45c7c7c + 8998bf6 commit cd8f084

File tree

7 files changed

+63
-8
lines changed

7 files changed

+63
-8
lines changed

autoload/jsdoc.vim

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" File: jsdoc.vim
22
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
33
" Modifyed: Shinya Ohyanagi <sohyanagi@gmail.com>
4-
" Version: 0.11.1
4+
" Version: 0.12.0
55
" WebPage: http://github.com/heavenshell/vim-jsdoc/
66
" Description: Generate JSDoc to your JavaScript file.
77
" License: BSD, see LICENSE for more details.
@@ -133,15 +133,21 @@ function! s:parse_type(args)
133133

134134
let type = s:trim(args[1])
135135
" Split keywaord args.
136+
let default_arg = ''
136137
if type =~# '='
137-
let type = s:trim(split(type, '=')[0])
138+
let values = split(type, '=')
139+
let type = s:trim(values[0])
140+
let default_arg = s:trim(values[1])
141+
endif
142+
if default_arg != ''
143+
" Default keywaord should be `[keyword=default]`.
144+
let val = printf('%s=%s', val, default_arg)
138145
endif
139146
call add(results, {'val': val, 'type': type})
140147
else
141148
call add(results, {'val': s:trim(arg), 'type': ''})
142149
endif
143150
endfor
144-
145151
return results
146152
endfunction
147153

@@ -199,7 +205,8 @@ function! s:hookArgs(lines, space, arg, hook, argType, argDescription) abort
199205
let l:description = a:argDescription !=# ''
200206
\ ? g:jsdoc_param_description_separator . a:argDescription
201207
\ : ''
202-
call add(a:lines, a:space . ' * @' . g:jsdoc_tags['param'] . ' ' . l:type . a:arg . l:description)
208+
let arg = s:parse_keyword_arg(a:arg)
209+
call add(a:lines, a:space . ' * @' . g:jsdoc_tags['param'] . ' ' . l:type . arg . l:description)
203210

204211
else
205212

@@ -221,7 +228,8 @@ function! s:hookArgs(lines, space, arg, hook, argType, argDescription) abort
221228
else
222229
let l:description = g:jsdoc_param_description_separator . a:argDescription
223230
endif
224-
call add(a:lines, a:space . ' * @' . g:jsdoc_tags['param'] . ' ' . l:type . a:arg . l:description)
231+
let arg = s:parse_keyword_arg(a:arg)
232+
call add(a:lines, a:space . ' * @' . g:jsdoc_tags['param'] . ' ' . l:type . arg . l:description)
225233

226234
endif
227235

@@ -309,6 +317,15 @@ function! s:extract_return_type(line)
309317
return l:return_type
310318
endfunction
311319

320+
function! s:parse_keyword_arg(arg)
321+
let result = a:arg
322+
if a:arg =~ '='
323+
let result = printf('[%s]', a:arg)
324+
endif
325+
326+
return result
327+
endfunction
328+
312329
function! jsdoc#insert() abort
313330
let l:line = getline('.')
314331
let l:indentCharSpace = ' '

doc/jsdoc.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*jsdoc.txt* Generate JSDoc to your JavaScript code.
22

3-
Version: 0.11.1
3+
Version: 0.12.0
44
Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
55
Modifyed: Shinya Ohynagi <sohyanagi@gmail.com>
66
Repository: http://github.com/heavenshell/vim-jsdoc/
@@ -301,6 +301,11 @@ g:jsdoc_user_defined_tags *g:jsdoc_user_defined_tags*
301301
>
302302
==============================================================================
303303
CHANGELOG *jsdoc-changelog*
304+
2017-01-28
305+
- Fix an optional parameter and default value.
306+
see https://github.com/heavenshell/vim-jsdoc/issues/64 details.
307+
(thx @codeinabox)
308+
304309
2016-10-30
305310
- Fix missing @param around single function argument.
306311
see https://github.com/heavenshell/vim-jsdoc/issues/61 details.

ftplugin/javascript/jsdoc.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" File: jsdoc.vim
22
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
33
" Modifyed: Shinya Ohyanagi <sohyanagi@gmail.com>
4-
" Version: 0.11.1
4+
" Version: 0.12.0
55
" WebPage: http://github.com/heavenshell/vim-jsdoc/
66
" Description: Generate JSDoc to your JavaScript file.
77
" License: BSD, see LICENSE for more details.

ftplugin/typescript/jsdoc.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" File: jsdoc.vim
22
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
33
" Modifyed: Shinya Ohyanagi <sohyanagi@gmail.com>
4-
" Version: 0.11.1
4+
" Version: 0.12.0
55
" WebPage: http://github.com/heavenshell/vim-jsdoc/
66
" Description: Generate JSDoc to your JavaScript file.
77
" License: BSD, see LICENSE for more details.

test/flow.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @flow
2+
function foo(arg1 :string, arg2: number): string {
3+
return ''
4+
}
5+
6+
interface Foo {
7+
foo: string
8+
}
9+
10+
type Bar = {
11+
bar: number
12+
}
13+
14+
class FooBar {
15+
props: Bar
16+
17+
foo (arg1: string, arg2: any): void {
18+
}
19+
20+
bar (arg1: number, arg2: Foo): any {
21+
return
22+
}
23+
}

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ function namedFunctionDeclaration(_a2, err) { }
1717

1818
function* namedGeneratorFunc(data) { }
1919

20+
function defaultParams(arg, arg1 = 'foo', arg2 = 100) {}
21+
2022
const namespace = {};
2123

2224
namespace.x0 = function (e) { }; // anonymous method

test/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ function union(): number | string {
1414
}
1515

1616
interface IFoo {
17+
foo?: string
18+
}
19+
20+
interface InterfaceBar extends IFoo {
1721
}
1822

1923
class Foo {
2024
}
2125

2226
class Bar extends Foo implements IFoo {
27+
private foo: number
28+
bar: string
2329
constructor(private arg1: string, public arg2: string) {
2430
super()
2531
}
2632
private foo(arg1: string, arg2: number = 0): void {
2733
}
2834
public _bar(): void {
2935
}
36+
public baz(arg1: string = 'foo', arg2: number = 100): void {
37+
}
3038
}
3139

3240
class Baz extends Foo implements IFoo {

0 commit comments

Comments
 (0)