Skip to content

Commit fed3dda

Browse files
committed
Create basic structures containing information about old and new comments.
1 parent 14432f5 commit fed3dda

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/index.es6

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,52 @@ function hasComment(contract, line) {
5656
}
5757
}
5858

59+
function updateComment(contract, commentLines, line) {
60+
if (hasComment(contract,line)) {
61+
62+
let newCommentsParams = [];
63+
let newCommentsMap = commentLines.reduce(function(map, obj) {
64+
let key = obj.match(/\/\/\/ @([a-zA-Z]*)\b/g)[0];
65+
if(key === "/// @param") {
66+
newCommentsParams.push(obj);
67+
} else map[key] = obj;
68+
return map;
69+
}, {});
70+
71+
let oldCommentsParams = [];
72+
let oldCommentsMap = {};
73+
let oldCommentPosition = line - 2;
74+
while (true) {
75+
let comment = contract.getLineAt(oldCommentPosition);
76+
if(comment.startsWith('/// @param')) {
77+
oldCommentsParams.push(comment)
78+
} else if(comment.startsWith('//')) {
79+
oldCommentsMap[comment.match(/\/\/\/ @([a-zA-Z]*)\b/g)[0]] = comment
80+
} else break;
81+
}
82+
83+
return true;
84+
}
85+
// let offsetCounter = commentLines.length + 1;
86+
// for(let l of commentLines) {
87+
// let currentLine = line - offsetCounter;
88+
// let currentComment = contract.getLineAt(currentLine).trim();
89+
// if (currentComment.startsWith('/// @param') && l.trim().startsWith('/// @param')) {
90+
// contract.removeLine(currentLine);
91+
// contract.insertLinesBefore(l.split(), currentLine);
92+
// }
93+
// offsetCounter--;
94+
// }
95+
// return true;
96+
// }
97+
return false;
98+
}
99+
59100
function insertComment(contract, node) {
60101
let comment = generator.generate(node);
61102
if (!comment) return;
62-
if (hasComment(contract, node.loc.start.line)) return;
63103
let commentLines = comment.split('\n');
104+
if (updateComment(contract, commentLines, node.loc.start.line)) return;
64105
commentLines = pad(
65106
node.loc.start.column,
66107
commentLines,

0 commit comments

Comments
 (0)