fix the name/scope of properties whose names include single quotes (#386)

This commit is contained in:
Jeff Williams 2013-04-17 18:08:27 -07:00
parent a3286e38bc
commit 5b219ababb
2 changed files with 23 additions and 2 deletions

View File

@ -157,8 +157,8 @@ exports.shorten = function(longname, forcedMemberof) {
// quoted strings in a longname are atomic, convert to tokens
var atoms = [], token;
// handle quoted names like foo["bar"]
longname = longname.replace(/(\[?".+?"\]?)/g, function($) {
// handle quoted names like foo["bar"] or foo['bar']
longname = longname.replace(/(\[?["'].+?["']\]?)/g, function($) {
var dot = '';
if ( /^\[/.test($) ) {
dot = '.';

View File

@ -1,3 +1,5 @@
/*global describe: true, expect: true, it: true */
describe("jsdoc/name", function() {
var jsdoc = {name: require('jsdoc/name'), doclet: require('jsdoc/doclet') };
@ -91,6 +93,15 @@ describe("jsdoc/name", function() {
expect(parts.scope).toEqual('.');
});
it('should work on bracketed stringy names with single quotes', function() {
var startName = "channels['#ops']",
parts = jsdoc.name.shorten(startName);
expect(parts.name).toBe("'#ops'");
expect(parts.memberof).toBe('channels');
expect(parts.scope).toBe('.');
});
it('should work on fully stringy names, like "foo.bar"', function() {
var startName = '"foo.bar"',
parts = jsdoc.name.shorten(startName);
@ -105,6 +116,16 @@ describe("jsdoc/name", function() {
expect(parts.scope).toEqual('');
});
it('should work on fully stringy names in single quotes, like \'foo.bar\'', function() {
var startName = "'foo.bar'",
parts = jsdoc.name.shorten(startName);
expect(parts.name).toBe("'foo.bar'");
expect(parts.longname).toBe("'foo.bar'");
expect(parts.memberof).toBe('');
expect(parts.scope).toBe('');
});
it('should find the variation', function() {
var startName = 'anim.fadein(2)',
parts = jsdoc.name.shorten(startName);