comment-parser 0.4.1 → 0.4.2

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/.travis.yml CHANGED
@@ -1,8 +1,6 @@
1
1
  language: node_js
2
2
  node_js:
3
+ - "8.5"
4
+ - "6.11"
3
5
  - "4.1"
4
6
  - "4.0"
5
- - "0.12"
6
- - "0.11"
7
- - "0.10"
8
- - "iojs"
package/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.4.2
2
+ - tolerate inconsistent lines alignment within block
3
+
1
4
  # v0.4.1
2
5
  - refactored parsing, allow to not start lines with "* " inside block
3
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-parser",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Generic JSDoc-like comment parser. ",
5
5
  "main": "index.js",
6
6
  "directories": {
package/parser.js CHANGED
@@ -12,8 +12,8 @@ function merge (/* ...objects */) {
12
12
  var res = {}
13
13
  var objs = Array.prototype.slice.call(arguments)
14
14
 
15
- while (objs.length) {
16
- obj = objs.shift()
15
+ for (var i = 0, l = objs.length; i < l; i++) {
16
+ obj = objs[i]
17
17
  for (k in obj) {
18
18
  if (obj.hasOwnProperty(k)) {
19
19
  res[k] = obj[k]
@@ -83,9 +83,9 @@ function parse_tag (str, parsers) {
83
83
  * Parses comment block (array of String lines)
84
84
  */
85
85
  function parse_block (source, opts) {
86
- function trim (s) {
87
- return opts.trim ? s.trim() : s
88
- }
86
+ var trim = opts.trim
87
+ ? function trim (s) { return s.trim() }
88
+ : function trim (s) { return s }
89
89
 
90
90
  var source_str = source
91
91
  .map(function (line) { return trim(line.source) })
@@ -211,10 +211,26 @@ function mkextract (opts) {
211
211
 
212
212
  // if we are on middle of comment block
213
213
  if (chunk) {
214
+ var lineStart = indent
215
+
216
+ // figure out if we slice from opening marker pos
217
+ // or line start is shifted to the left
218
+ var nonSpaceChar = line.match(/\S/)
219
+
220
+ // skip for the first line starting with /** (fresh chunk)
221
+ // it always has the right indentation
222
+ if (chunk.length > 0 && nonSpaceChar) {
223
+ if (nonSpaceChar[0] === '*') {
224
+ lineStart = nonSpaceChar.index + 2
225
+ } else if (nonSpaceChar.index < indent) {
226
+ lineStart = nonSpaceChar.index
227
+ }
228
+ }
229
+
214
230
  // slice the line until end or until closing marker start
215
- chunk = chunk.concat({
231
+ chunk.push({
216
232
  number: number,
217
- source: line.slice(indent, endPos === -1 ? line.length : endPos)
233
+ source: line.slice(lineStart, endPos === -1 ? line.length : endPos)
218
234
  })
219
235
 
220
236
  // finalize block if end marker detected
@@ -238,7 +254,7 @@ module.exports = function parse (source, opts) {
238
254
  var extract = mkextract(opts)
239
255
  var lines = source.split(/\n/)
240
256
 
241
- while (lines.length) {
257
+ for (var i = 0, l = lines.length; i < l; i++) {
242
258
  block = extract(lines.shift())
243
259
  if (block) {
244
260
  blocks.push(block)
@@ -689,4 +689,100 @@ describe('Comment string parsing', function () {
689
689
  }]
690
690
  })
691
691
  })
692
+
693
+ it('should parse doc block with bound forced to the left', function () {
694
+ expect(parse(function () {
695
+ /**
696
+ * Description text
697
+ * @tag tagname Tag description
698
+ */
699
+ })[0])
700
+ .to.eql({
701
+ description: 'Description text',
702
+ source: 'Description text\n@tag tagname Tag description',
703
+ line: 1,
704
+ tags: [{
705
+ tag: 'tag',
706
+ name: 'tagname',
707
+ optional: false,
708
+ description: 'Tag description',
709
+ type: '',
710
+ line: 3,
711
+ source: '@tag tagname Tag description'
712
+ }]
713
+ })
714
+ })
715
+
716
+ it('should parse doc block with bound forced to the right', function () {
717
+ expect(parse(function () {
718
+ /**
719
+ * Description text
720
+ * @tag tagname Tag description
721
+ */
722
+ })[0])
723
+ .to.eql({
724
+ description: 'Description text',
725
+ source: 'Description text\n@tag tagname Tag description',
726
+ line: 1,
727
+ tags: [{
728
+ tag: 'tag',
729
+ name: 'tagname',
730
+ optional: false,
731
+ description: 'Tag description',
732
+ type: '',
733
+ line: 3,
734
+ source: '@tag tagname Tag description'
735
+ }]
736
+ })
737
+ })
738
+
739
+ it('should parse doc block with soft bound', function () {
740
+ expect(parse(function () {
741
+ /**
742
+ Description text
743
+ another line
744
+ @tag tagname Tag description
745
+ */
746
+ })[0])
747
+ .to.eql({
748
+ description: 'Description text\nanother line',
749
+ source: 'Description text\nanother line\n@tag tagname Tag description',
750
+ line: 1,
751
+ tags: [{
752
+ tag: 'tag',
753
+ name: 'tagname',
754
+ optional: false,
755
+ description: 'Tag description',
756
+ type: '',
757
+ line: 4,
758
+ source: '@tag tagname Tag description'
759
+ }]
760
+ })
761
+ })
762
+
763
+ it('should parse doc block with soft bound respecting `opts.trim = false`', function () {
764
+ expect(parse(function () {
765
+ /**
766
+ Description text
767
+ another line
768
+ @tag tagname Tag description
769
+ */
770
+ }, {
771
+ trim: false
772
+ })[0])
773
+ .to.eql({
774
+ description: '\nDescription text\n another line',
775
+ source: '\nDescription text\n another line\n@tag tagname Tag description\n',
776
+ line: 1,
777
+ tags: [{
778
+ tag: 'tag',
779
+ name: 'tagname',
780
+ optional: false,
781
+ description: 'Tag description\n',
782
+ type: '',
783
+ line: 4,
784
+ source: '@tag tagname Tag description\n'
785
+ }]
786
+ })
787
+ })
692
788
  })
package/.jshintrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "node": true,
3
- "strict": true,
4
- "maxlen": 100,
5
- "undef": true,
6
- "unused": true,
7
- "onecase": true,
8
- "lastsemic": true,
9
- "latedef" : true,
10
- "indent": 2
11
- }