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 +3 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/parser.js +17 -1
- package/tests/parse.js +1 -1
- package/tests/parse.spec.js +79 -0
- package/.npmignore +0 -15
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/package.json
CHANGED
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
|
-
|
|
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
package/tests/parse.spec.js
CHANGED
|
@@ -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
|
})
|