mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added boolean trus and false to the list of @default values recognised from the code source. Added support for invalid variable name characters in the keys of objectliterals, plus tests.
This commit is contained in:
parent
20416aa65c
commit
2b3553dd64
@ -95,7 +95,7 @@
|
|||||||
*/
|
*/
|
||||||
exports.Doclet.prototype.setLongname = function(name) {
|
exports.Doclet.prototype.setLongname = function(name) {
|
||||||
if (/^<global>\.?/.test(name)) { name = name.replace(/^<global>\.?/, ''); }
|
if (/^<global>\.?/.test(name)) { name = name.replace(/^<global>\.?/, ''); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The fully resolved symbol name.
|
The fully resolved symbol name.
|
||||||
@type string
|
@type string
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
memberof = doclet.memberof || '',
|
memberof = doclet.memberof || '',
|
||||||
about = {},
|
about = {},
|
||||||
parentDoc;
|
parentDoc;
|
||||||
|
|
||||||
name = name? (''+name).replace(/\.prototype\.?/g, '#') : '';
|
name = name? (''+name).replace(/\.prototype\.?/g, '#') : '';
|
||||||
|
|
||||||
// member of a var in an outer scope?
|
// member of a var in an outer scope?
|
||||||
@ -172,6 +172,7 @@
|
|||||||
scope = scope.replace('@{'+i+'}@', atoms[i]);
|
scope = scope.replace('@{'+i+'}@', atoms[i]);
|
||||||
name = name.replace('@{'+i+'}@', atoms[i]);
|
name = name.replace('@{'+i+'}@', atoms[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
return {longname: longname, memberof: memberof, scope: scope, name: name, variation: variation};
|
return {longname: longname, memberof: memberof, scope: scope, name: name, variation: variation};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -268,7 +268,7 @@
|
|||||||
currentParser.refs['astnode'+e.code.node.hashCode()] = e.doclet; // allow lookup from value => doclet
|
currentParser.refs['astnode'+e.code.node.hashCode()] = e.doclet; // allow lookup from value => doclet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.type === Token.COLON) {
|
else if (node.type === Token.COLON) { // assignment within an object literal
|
||||||
e = {
|
e = {
|
||||||
id: 'astnode'+node.hashCode(), // the id of the COLON node
|
id: 'astnode'+node.hashCode(), // the id of the COLON node
|
||||||
comment: String(node.left.jsDoc||'@undocumented'),
|
comment: String(node.left.jsDoc||'@undocumented'),
|
||||||
@ -376,8 +376,9 @@
|
|||||||
function aboutNode(node) {
|
function aboutNode(node) {
|
||||||
about = {};
|
about = {};
|
||||||
|
|
||||||
if (node.type == Token.FUNCTION /*&& String(node.name) !== ''*/) {
|
if (node.type == Token.FUNCTION) {
|
||||||
about.name = '' + node.name;
|
about.name = '' + node.name;
|
||||||
|
|
||||||
about.type = 'function';
|
about.type = 'function';
|
||||||
about.node = node;
|
about.node = node;
|
||||||
|
|
||||||
@ -402,6 +403,13 @@
|
|||||||
|
|
||||||
if (node.type === Token.ASSIGN || node.type === Token.COLON) {
|
if (node.type === Token.ASSIGN || node.type === Token.COLON) {
|
||||||
about.name = nodeToString(node.left);
|
about.name = nodeToString(node.left);
|
||||||
|
if (node.type === Token.COLON) {
|
||||||
|
|
||||||
|
// objlit keys with unsafe variable-name characters must be quoted
|
||||||
|
if (!/^[$_a-z][$_a-z0-9]*$/i.test(about.name) ) {
|
||||||
|
about.name = '"'+about.name.replace(/"/g, '\\"')+'"';
|
||||||
|
}
|
||||||
|
}
|
||||||
about.node = node.right;
|
about.node = node.right;
|
||||||
about.value = nodeToString(about.node);
|
about.value = nodeToString(about.node);
|
||||||
about.type = getTypeName(node.right);
|
about.type = getTypeName(node.right);
|
||||||
|
|||||||
@ -123,12 +123,16 @@
|
|||||||
doclet.defaultvalue = tag.value;
|
doclet.defaultvalue = tag.value;
|
||||||
}
|
}
|
||||||
else if (doclet.meta && doclet.meta.code && typeof doclet.meta.code.value !== 'undefined') {
|
else if (doclet.meta && doclet.meta.code && typeof doclet.meta.code.value !== 'undefined') {
|
||||||
if (doclet.meta.code.type && /STRING|NUMBER|NAME/.test(doclet.meta.code.type)) {
|
if (doclet.meta.code.type && /STRING|NUMBER|NAME|TRUE|FALSE/.test(doclet.meta.code.type)) {
|
||||||
doclet.defaultvalue = doclet.meta.code.value;
|
doclet.defaultvalue = doclet.meta.code.value;
|
||||||
if (doclet.meta.code.type === 'STRING') {
|
if (doclet.meta.code.type === 'STRING') {
|
||||||
// TODO: handle escaped quotes in values
|
// TODO: handle escaped quotes in values
|
||||||
doclet.defaultvalue = '"'+doclet.defaultvalue.replace(/"/g, '\\"')+'"'
|
doclet.defaultvalue = '"'+doclet.defaultvalue.replace(/"/g, '\\"')+'"'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (doclet.defaultvalue === 'TRUE' || doclet.defaultvalue == 'FALSE') {
|
||||||
|
doclet.defaultvalue = doclet.defaultvalue.toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (doclet.meta.code.type === 'NULL') {
|
else if (doclet.meta.code.type === 'NULL') {
|
||||||
// TODO: handle escaped quotes in values
|
// TODO: handle escaped quotes in values
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
|
/** @namespace */
|
||||||
|
var chat = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@namespace
|
@namespace
|
||||||
@name chat."#channel"
|
|
||||||
*/
|
*/
|
||||||
chat["#channel"] = {};
|
chat["#channel"] = {};
|
||||||
|
|
||||||
@ -8,7 +10,7 @@ chat["#channel"] = {};
|
|||||||
/**
|
/**
|
||||||
@property
|
@property
|
||||||
@type {boolean}
|
@type {boolean}
|
||||||
@name chat."#channel".open
|
@defaultvalue
|
||||||
*/
|
*/
|
||||||
chat["#channel"].open = true;
|
chat["#channel"].open = true;
|
||||||
|
|
||||||
|
|||||||
10
test/cases/quotename2.js
Normal file
10
test/cases/quotename2.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/** @namespace */
|
||||||
|
var contacts = {
|
||||||
|
|
||||||
|
/** @namespace */
|
||||||
|
'say-"hello"@example.com': {
|
||||||
|
|
||||||
|
/** document me */
|
||||||
|
"username": 'Sue Smart'
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -130,6 +130,8 @@ testFile('test/t/cases/moduletag.js');
|
|||||||
testFile('test/t/cases/moduletag2.js');
|
testFile('test/t/cases/moduletag2.js');
|
||||||
testFile('test/t/cases/paramtag.js');
|
testFile('test/t/cases/paramtag.js');
|
||||||
testFile('test/t/cases/privatetag.js');
|
testFile('test/t/cases/privatetag.js');
|
||||||
|
testFile('test/t/cases/quotename.js');
|
||||||
|
testFile('test/t/cases/quotename2.js');
|
||||||
testFile('test/t/cases/readonlytag.js');
|
testFile('test/t/cases/readonlytag.js');
|
||||||
testFile('test/t/cases/requirestag.js');
|
testFile('test/t/cases/requirestag.js');
|
||||||
testFile('test/t/cases/returnstag.js');
|
testFile('test/t/cases/returnstag.js');
|
||||||
|
|||||||
11
test/t/cases/quotename.js
Normal file
11
test/t/cases/quotename.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
(function() {
|
||||||
|
var docSet = testhelpers.getDocSetFromFile('test/cases/quotename.js'),
|
||||||
|
found1 = docSet.getByLongname('chat.\"#channel\".open')[0];
|
||||||
|
|
||||||
|
// dump(docSet);
|
||||||
|
|
||||||
|
test('When a member is quoted in square brackets.', function() {
|
||||||
|
assert.equal(found1.name, 'open', 'The short name should be correct.');
|
||||||
|
assert.equal(found1.memberof, 'chat.\"#channel\"', 'The memberof should be correct.');
|
||||||
|
});
|
||||||
|
})();
|
||||||
11
test/t/cases/quotename2.js
Normal file
11
test/t/cases/quotename2.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
(function() {
|
||||||
|
var docSet = testhelpers.getDocSetFromFile('test/cases/quotename2.js'),
|
||||||
|
found1 = docSet.getByLongname("contacts.\"say-\\\"hello\\\"@example.com\".username")[0];
|
||||||
|
|
||||||
|
// dump(docSet);
|
||||||
|
|
||||||
|
test('When a key name of a member of an objlit is quoted.', function() {
|
||||||
|
assert.equal(found1.name, 'username', 'The short name should be correct.');
|
||||||
|
assert.equal(found1.memberof, "contacts.\"say-\\\"hello\\\"@example.com\"", 'The memberof should be correct.');
|
||||||
|
});
|
||||||
|
})();
|
||||||
Loading…
x
Reference in New Issue
Block a user