comment-parser 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.5.0
2
+ - line wrapping control with `opts.join`
3
+
1
4
  # v0.4.2
2
5
  - tolerate inconsistent lines alignment within block
3
6
 
package/README.md CHANGED
@@ -160,3 +160,4 @@ This would produce following:
160
160
  - [Evgeny Reznichenko](https://github.com/zxcabs)
161
161
  - [Jordan Harband](https://github.com/ljharb)
162
162
  - [Sergii Iavorskyi](https://github.com/yavorskiy)
163
+ - [tengattack](https://github.com/tengattack)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-parser",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Generic JSDoc-like comment parser. ",
5
5
  "main": "index.js",
6
6
  "directories": {
package/parser.js CHANGED
@@ -105,7 +105,20 @@ function parse_block (source, opts) {
105
105
  tags.push({source: [line.source], line: line.number})
106
106
  } else {
107
107
  var tag = tags[tags.length - 1]
108
- tag.source.push(line.source)
108
+ if (opts.join !== undefined && opts.join !== false && opts.join !== 0 &&
109
+ !line.startWithStar && tag.source.length > 0) {
110
+ var source
111
+ if (typeof opts.join === 'string') {
112
+ source = opts.join + line.source.replace(/^\s+/, '')
113
+ } else if (typeof opts.join === 'number') {
114
+ source = line.source
115
+ } else {
116
+ source = ' ' + line.source.replace(/^\s+/, '')
117
+ }
118
+ tag.source[tag.source.length - 1] += source
119
+ } else {
120
+ tag.source.push(line.source)
121
+ }
109
122
  }
110
123
 
111
124
  return tags
@@ -212,6 +225,7 @@ function mkextract (opts) {
212
225
  // if we are on middle of comment block
213
226
  if (chunk) {
214
227
  var lineStart = indent
228
+ var startWithStar = false
215
229
 
216
230
  // figure out if we slice from opening marker pos
217
231
  // or line start is shifted to the left
@@ -222,6 +236,7 @@ function mkextract (opts) {
222
236
  if (chunk.length > 0 && nonSpaceChar) {
223
237
  if (nonSpaceChar[0] === '*') {
224
238
  lineStart = nonSpaceChar.index + 2
239
+ startWithStar = true
225
240
  } else if (nonSpaceChar.index < indent) {
226
241
  lineStart = nonSpaceChar.index
227
242
  }
@@ -230,6 +245,7 @@ function mkextract (opts) {
230
245
  // slice the line until end or until closing marker start
231
246
  chunk.push({
232
247
  number: number,
248
+ startWithStar: startWithStar,
233
249
  source: line.slice(lineStart, endPos === -1 ? line.length : endPos)
234
250
  })
235
251
 
package/tests/parse.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * 0 function() {
5
5
  * 1 // source with comments
6
6
  * 2 }
7
- *
7
+ *
8
8
  */
9
9
 
10
10
  var parse = require('../index')
@@ -785,4 +785,83 @@ describe('Comment string parsing', function () {
785
785
  }]
786
786
  })
787
787
  })
788
+
789
+ it('should parse multiline without star as same line respecting `opts.join = true`', function () {
790
+ expect(parse(function () {
791
+ /**
792
+ * @tag name
793
+ * description
794
+ same line
795
+ */
796
+ }, {
797
+ join: true
798
+ })[0])
799
+ .to.eql({
800
+ line: 1,
801
+ description: '',
802
+ source: '@tag name\ndescription\nsame line',
803
+ tags: [{
804
+ tag: 'tag',
805
+ line: 2,
806
+ type: '',
807
+ name: 'name',
808
+ description: 'description same line',
809
+ source: '@tag name\ndescription same line',
810
+ optional: false
811
+ }]
812
+ })
813
+ })
814
+
815
+ it('should parse multiline without star as same line respecting `opts.join = "\\t"`', function () {
816
+ expect(parse(function () {
817
+ /**
818
+ * @tag name
819
+ * description
820
+ same line
821
+ */
822
+ }, {
823
+ join: '\t'
824
+ })[0])
825
+ .to.eql({
826
+ line: 1,
827
+ description: '',
828
+ source: '@tag name\ndescription\nsame line',
829
+ tags: [{
830
+ tag: 'tag',
831
+ line: 2,
832
+ type: '',
833
+ name: 'name',
834
+ description: 'description\tsame line',
835
+ source: '@tag name\ndescription\tsame line',
836
+ optional: false
837
+ }]
838
+ })
839
+ })
840
+
841
+ it('should parse multiline without star as same line with intent respecting `opts.join = 1` and `opts.trim = false`', function () {
842
+ expect(parse(function () {
843
+ /**
844
+ * @tag name
845
+ * description
846
+ intent same line
847
+ */
848
+ }, {
849
+ join: 1,
850
+ trim: false
851
+ })[0])
852
+ .to.eql({
853
+ line: 1,
854
+ description: '',
855
+ source: '\n@tag name\ndescription\n intent same line\n',
856
+ tags: [{
857
+ tag: 'tag',
858
+ line: 2,
859
+ type: '',
860
+ name: 'name',
861
+ description: 'description intent same line\n',
862
+ source: '@tag name\ndescription intent same line\n',
863
+ optional: false
864
+ }]
865
+ })
866
+ })
788
867
  })
package/.npmignore DELETED
@@ -1,15 +0,0 @@
1
- lib-cov
2
- *.seed
3
- *.log
4
- *.csv
5
- *.dat
6
- *.out
7
- *.pid
8
- *.gz
9
-
10
- pids
11
- logs
12
- results
13
-
14
- npm-debug.log
15
- node_modules