Skip to content

Commit d16e849

Browse files
committed
type definitions made optional, closes #5
1 parent 57d6a62 commit d16e849

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ Code above will transform into:
8888
String a;
8989
```
9090

91+
However, you can omit any type definitions. Then default type `var` will be used.
92+
9193
### Functions
9294

93-
Type definition for function arguments done the same way as for variables. Also you're able define functions's return type.
95+
Type definition for function arguments done the same way as for variables. Also you're able define functions's return type, however, this is still optional.
9496

9597
```javascript
9698
/*!

src/extractToken.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,24 @@ const extractClassMethod = line => {
7070
};
7171

7272
const extractComment = comment_array => {
73-
const oneliner_expr = /^\s*\/\/\!\s*type\:(\w+)\s*(.*)$/;
73+
const oneliner_expr = /^\s*\/\/\!\s*(type\:(\w+))?\s*(.*)$/;
7474
const brief_expr = /^\s*\*\s*@brief\s*(.*)$/;
75-
const param_expr = /^\s*\*\s*@param\s*type\:(\w+)\s*(\w+)\s*(.*)$/;
76-
const return_expr = /^\s*\*\s*@return\s*type\:(\w+)\s*(.*)$/;
75+
const param_expr = /^\s*\*\s*@param\s*(type\:(\w+))?\s*(\w+)\s*(.*)$/;
76+
const return_expr = /^\s*\*\s*@return\s*(type\:(\w+))?\s*(.*)$/;
7777

7878
return comment_array.reduce((comment, line) => {
7979
const oneliner_match = line.match(oneliner_expr);
8080
if (oneliner_match) {
81-
comment.brief = oneliner_match[2];
82-
comment.type = oneliner_match[1];
81+
const [_, __, type, brief] = oneliner_match;
82+
comment.brief = brief;
83+
comment.type = type;
8384
return comment;
8485
}
8586

8687
const brief_match = line.match(brief_expr);
8788
if (brief_match) {
88-
comment.brief = brief_match[1];
89+
const [_, brief] = brief_match;
90+
comment.brief = brief;
8991
return comment;
9092
}
9193

@@ -94,17 +96,15 @@ const extractComment = comment_array => {
9496
if (!comment.params) {
9597
comment.params = {};
9698
}
97-
comment.params[param_match[2]] = {
98-
brief: param_match[3],
99-
name: param_match[2],
100-
type: param_match[1],
101-
};
99+
const [_, __, type, name, brief] = param_match;
100+
comment.params[name] = { brief, name, type };
102101
return comment;
103102
}
104103

105104
const return_match = line.match(return_expr);
106105
if (return_match) {
107-
comment.return = { brief: return_match[2], type: return_match[1] };
106+
const [_, __, type, brief] = return_match;
107+
comment.return = { brief, type };
108108
}
109109

110110
return comment;

0 commit comments

Comments
 (0)