mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added doclet parsing for object literal getters and setters (#100)
This commit is contained in:
parent
b8a7d977b1
commit
9196f730de
@ -224,7 +224,8 @@ function aboutNode(node) {
|
||||
about.type = 'undefined';
|
||||
}
|
||||
}
|
||||
else if (node.type === Token.ASSIGN || node.type === Token.COLON) {
|
||||
else if (node.type === Token.ASSIGN || node.type === Token.COLON ||
|
||||
node.type === Token.GET || node.type === Token.SET) {
|
||||
about.name = nodeToString(node.left);
|
||||
if (node.type === Token.COLON) {
|
||||
|
||||
@ -235,7 +236,13 @@ function aboutNode(node) {
|
||||
}
|
||||
about.node = node.right;
|
||||
about.value = nodeToString(about.node);
|
||||
|
||||
// Getter and setter functions should be treated as properties
|
||||
if (node.type === Token.GET || node.type === Token.SET) {
|
||||
about.type = nodeToString(node);
|
||||
} else {
|
||||
about.type = getTypeName(node.right);
|
||||
}
|
||||
|
||||
if (about.type === 'FUNCTION' && about.node.name) {
|
||||
about.node.type = tkn.NAMEDFUNCTIONSTATEMENT;
|
||||
@ -363,6 +370,18 @@ function visitNode(node) {
|
||||
finishers: [currentParser.addDocletRef, currentParser.resolveEnum]
|
||||
};
|
||||
}
|
||||
else if (node.type === Token.GET || node.type === Token.SET) { // assignment within an object literal
|
||||
e = {
|
||||
id: 'astnode'+node.hashCode(), // the id of the GET/SET node
|
||||
comment: String(node.left.getJsDoc()||'@undocumented'),
|
||||
lineno: node.left.getLineno(),
|
||||
filename: currentSourceName,
|
||||
astnode: node,
|
||||
code: aboutNode(node),
|
||||
event: "symbolFound",
|
||||
finishers: [currentParser.addDocletRef]
|
||||
};
|
||||
}
|
||||
else if (node.type == Token.VAR || node.type == Token.LET || node.type == Token.CONST) {
|
||||
|
||||
if (node.variables) {
|
||||
|
||||
37
test/fixtures/getset.js
vendored
Normal file
37
test/fixtures/getset.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/** @class */
|
||||
var Person = makeClass(
|
||||
/** @lends Person# */
|
||||
{
|
||||
/** Set up initial values. */
|
||||
initialize: function(name) {
|
||||
},
|
||||
|
||||
/** Speak a message. */
|
||||
say: function(message) {
|
||||
return this.name + " says: " + message;
|
||||
},
|
||||
|
||||
/**
|
||||
* The name of the person.
|
||||
* @type {string}
|
||||
*/
|
||||
get name() {
|
||||
return this._name;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
* @param val
|
||||
*/
|
||||
set name(val) {
|
||||
this._name = name;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
get age() {
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
);
|
||||
23
test/specs/documentation/getset.js
Normal file
23
test/specs/documentation/getset.js
Normal file
@ -0,0 +1,23 @@
|
||||
describe("When a getter or setter is the child of an object literal", function () {
|
||||
var docSet = jasmine.getDocSetFromFile("test/fixtures/getset.js"),
|
||||
foundName = docSet.getByLongname("Person#name"),
|
||||
foundAge = docSet.getByLongname("Person#age");
|
||||
|
||||
it("should have a doclet with the correct longname", function () {
|
||||
expect(foundName.length).toEqual(2);
|
||||
expect(foundAge.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("should have a doclet with the correct name", function () {
|
||||
expect(foundName[0].name).toEqual("name");
|
||||
expect(foundName[1].name).toEqual("name");
|
||||
expect(foundAge[0].name).toEqual("age");
|
||||
});
|
||||
|
||||
it("should have the correct memberof", function () {
|
||||
expect(foundName[0].memberof).toEqual("Person");
|
||||
expect(foundName[1].memberof).toEqual("Person");
|
||||
expect(foundAge[0].memberof).toEqual("Person");
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user