Skip to content

Commit 8d96531

Browse files
authored
Merge pull request #5 from NodeFactoryIo/hotfix/old-generated-single-line-comments
Fix problem when generating comments on edited contract
2 parents 181d247 + f532865 commit 8d96531

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/lib/contract/contract-comment.es6

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pad } from '../utils/string-utils';
1+
import {pad} from '../utils/string-utils';
22
import CommentsGenerator from '../generators/comments-generator';
33

44
// regexps
@@ -31,11 +31,11 @@ export class ContractComment {
3131
// extract old comments
3232
let oldCommentsParams = [];
3333
let oldCommentsMap = {};
34-
let oldCommentPosition = line - 2;
34+
let oldCommentPosition = line - 1;
3535
while (true) {
3636
let comment = this.contract.getLineAt(oldCommentPosition).trim();
3737
if (comment.startsWith(parameterCommentRegex)) {
38-
oldCommentsParams.push({ line: oldCommentPosition, value: comment });
38+
oldCommentsParams.push({line: oldCommentPosition, value: comment});
3939
} else if (comment.startsWith('//')) {
4040
oldCommentsMap[comment.match(generatedCommentRegex)[0]] = comment;
4141
} else if (!comment.startsWith('function')) {
@@ -58,16 +58,12 @@ export class ContractComment {
5858
}, {});
5959
// update params if changed
6060
if (newCommentsParams.length) {
61-
for (let k in oldCommentsMap) {
62-
const c = !k;
63-
if (c in newCommentsMap) {
64-
return true;
65-
}
61+
if (Object.keys(oldCommentsMap).length !== Object.keys(newCommentsMap).length) {
62+
return true;
6663
}
6764
let firstCommentLine = oldCommentsParams
6865
.reduce((min, b) => Math.min(min, b.line), oldCommentsParams[0].line);
69-
// remove old params comments and save additional information about
70-
// params
66+
// remove old params comments and save addi. information about params
7167
let savedComments = {};
7268
for (let oldComment of oldCommentsParams) {
7369
this.contract.removeLine(firstCommentLine);

0 commit comments

Comments
 (0)