mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
use a 'range' property in parser events rather than 'linelength' and 'absposition' (#346)
This commit is contained in:
parent
21dbd5804f
commit
f16fa3beb7
@ -300,6 +300,20 @@ function getBasename(name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** @private
|
||||
* @memberof module:src/parser.Parser
|
||||
* @param {object} node
|
||||
* @return {Array.<number>} Start and end lines.
|
||||
*/
|
||||
function getRange(node) {
|
||||
var range = [];
|
||||
|
||||
range[0] = parseInt(String(node.getAbsolutePosition()), 10);
|
||||
range[1] = range[0] + parseInt(String(node.getLength()), 10);
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
/** @private
|
||||
* @memberof module:src/parser.Parser
|
||||
*/
|
||||
@ -312,17 +326,7 @@ exports.Parser.prototype._makeEvent = function(node, extras) {
|
||||
id: extras.id || 'astnode' + node.hashCode(),
|
||||
comment: extras.comment || String(node.getJsDoc() || '@undocumented'),
|
||||
lineno: extras.lineno || node.left.getLineno(),
|
||||
range: (function() {
|
||||
var range = [];
|
||||
if (extras.range) {
|
||||
range = extras.range;
|
||||
}
|
||||
else {
|
||||
range[0] = parseInt(String(node.getAbsolutePosition()), 10);
|
||||
range[1] = range[0] + parseInt(String(node.getLength()), 10);
|
||||
}
|
||||
return range;
|
||||
})(),
|
||||
range: extras.range || getRange(node),
|
||||
filename: extras.filename || this._currentSourceName,
|
||||
astnode: extras.astnode || node,
|
||||
code: extras.code || aboutNode(node),
|
||||
@ -388,8 +392,7 @@ exports.Parser.prototype._visitNode = function(node) {
|
||||
comment: commentSrc,
|
||||
lineno: comment.getLineno(),
|
||||
filename: this._currentSourceName,
|
||||
linelength: comment.getLength(),
|
||||
absposition: comment.getAbsolutePosition()
|
||||
range: getRange(comment)
|
||||
};
|
||||
|
||||
this.emit('jsdocCommentFound', e, this);
|
||||
@ -432,9 +435,7 @@ exports.Parser.prototype._visitNode = function(node) {
|
||||
}
|
||||
|
||||
extras = {
|
||||
lineno: node.getLineno(),
|
||||
linelength: node.getLength(),
|
||||
absposition: node.getAbsolutePosition()
|
||||
lineno: node.getLineno()
|
||||
};
|
||||
e = this._makeEvent(node, extras);
|
||||
|
||||
@ -442,9 +443,7 @@ exports.Parser.prototype._visitNode = function(node) {
|
||||
}
|
||||
else if (node.type == Token.FUNCTION || node.type == tkn.NAMEDFUNCTIONSTATEMENT) {
|
||||
extras = {
|
||||
lineno: node.getLineno(),
|
||||
linelength: node.getLength(),
|
||||
absposition: node.getAbsolutePosition()
|
||||
lineno: node.getLineno()
|
||||
};
|
||||
e = this._makeEvent(node, extras);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user