revert part of 5fa636 due to performance hit (#830)

This commit is contained in:
Jeff Williams 2014-12-07 16:37:28 -08:00
parent 3162215c9a
commit eafc56de23
3 changed files with 19 additions and 50 deletions

View File

@ -108,7 +108,7 @@ function parentIsClass(parent) {
function staticToInstance(doclet) { function staticToInstance(doclet) {
var parts = name.shorten(doclet.longname); var parts = name.shorten(doclet.longname);
parts.scopePunc = name.SCOPE.PUNC.INSTANCE; parts.scope = name.SCOPE.PUNC.INSTANCE;
doclet.longname = name.combineName(parts); doclet.longname = name.combineName(parts);
doclet.scope = name.SCOPE.NAMES.INSTANCE; doclet.scope = name.SCOPE.NAMES.INSTANCE;
} }

View File

@ -8,7 +8,6 @@
var _ = require('underscore'); var _ = require('underscore');
var escape = require('escape-string-regexp'); var escape = require('escape-string-regexp');
var util = require('util');
var hasOwnProp = Object.prototype.hasOwnProperty; var hasOwnProp = Object.prototype.hasOwnProperty;
@ -150,12 +149,12 @@ exports.resolve = function(doclet) {
doclet.setLongname(doclet.name); doclet.setLongname(doclet.name);
delete doclet.memberof; delete doclet.memberof;
} }
else if (about.scopePunc) { else if (about.scope) {
if (about.memberof === LONGNAMES.GLOBAL) { // via @memberof <global> ? if (about.memberof === LONGNAMES.GLOBAL) { // via @memberof <global> ?
doclet.scope = SCOPE.NAMES.GLOBAL; doclet.scope = SCOPE.NAMES.GLOBAL;
} }
else { else {
doclet.scope = puncToScope[about.scopePunc]; doclet.scope = puncToScope[about.scope];
} }
} }
else if (doclet.name && doclet.memberof && !doclet.longname) { else if (doclet.name && doclet.memberof && !doclet.longname) {
@ -198,25 +197,6 @@ exports.applyNamespace = function(longname, ns) {
return longname; return longname;
}; };
function NameAtoms(props) {
var scopeDeprecated = 'The "scope" property returned by name.shorten() is deprecated. ' +
'Use the "scopePunc" property instead.';
var self = this;
Object.keys(props).forEach(function(prop) {
self[prop] = props[prop];
});
Object.defineProperty(this, 'scope', {
get: util.deprecate(function() {
return this.scopePunc;
}, scopeDeprecated),
set: util.deprecate(function(value) {
this.scopePunc = value;
}, scopeDeprecated)
});
}
// TODO: docs // TODO: docs
function atomize(longname, sliceChars, forcedMemberof) { function atomize(longname, sliceChars, forcedMemberof) {
var i; var i;
@ -280,13 +260,13 @@ function atomize(longname, sliceChars, forcedMemberof) {
name = name.replace('@{' + i + '}@', tokens[i]); name = name.replace('@{' + i + '}@', tokens[i]);
} }
return new NameAtoms({ return {
longname: longname, longname: longname,
memberof: memberof, memberof: memberof,
scopePunc: scopePunc, scope: scopePunc,
name: name, name: name,
variation: variation variation: variation
}); };
} }
// TODO: deprecate exports.shorten in favor of a better name // TODO: deprecate exports.shorten in favor of a better name
@ -304,7 +284,7 @@ exports.shorten = function(longname, forcedMemberof) {
exports.combineName = function(parts) { exports.combineName = function(parts) {
return '' + return '' +
(parts.memberof || '') + (parts.memberof || '') +
(parts.scopePunc || '') + (parts.scope || '') +
(parts.name || '') + (parts.name || '') +
(parts.variation || ''); (parts.variation || '');
}; };
@ -330,7 +310,7 @@ function splitLongname(longname, options) {
} }
currentNameInfo = nameInfo[previousName] = atomize(previousName, splitters); currentNameInfo = nameInfo[previousName] = atomize(previousName, splitters);
previousName = currentNameInfo.memberof; previousName = currentNameInfo.memberof;
chunks.push(currentNameInfo.scopePunc + currentNameInfo.name); chunks.push(currentNameInfo.scope + currentNameInfo.name);
} while (previousName); } while (previousName);
return { return {

View File

@ -91,13 +91,13 @@ describe('jsdoc/name', function() {
}); });
describe('shorten', function() { describe('shorten', function() {
it('should break up a longname into the correct memberof, name and scopePunc parts', function() { it('should break up a longname into the correct memberof, name and scope parts', function() {
var startName = 'lib.Panel#open'; var startName = 'lib.Panel#open';
var parts = jsdoc.name.shorten(startName); var parts = jsdoc.name.shorten(startName);
expect(parts.name).toEqual('open'); expect(parts.name).toEqual('open');
expect(parts.memberof).toEqual('lib.Panel'); expect(parts.memberof).toEqual('lib.Panel');
expect(parts.scopePunc).toEqual('#'); expect(parts.scope).toEqual('#');
}); });
it('should work on static names', function() { it('should work on static names', function() {
@ -106,7 +106,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('getVisible'); expect(parts.name).toEqual('getVisible');
expect(parts.memberof).toEqual('elements.selected'); expect(parts.memberof).toEqual('elements.selected');
expect(parts.scopePunc).toEqual('.'); expect(parts.scope).toEqual('.');
}); });
it('should work on protoyped names', function() { it('should work on protoyped names', function() {
@ -115,7 +115,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('$element'); expect(parts.name).toEqual('$element');
expect(parts.memberof).toEqual('Validator'); expect(parts.memberof).toEqual('Validator');
expect(parts.scopePunc).toEqual('#'); expect(parts.scope).toEqual('#');
}); });
it('should work on inner names', function() { it('should work on inner names', function() {
@ -124,7 +124,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('_onclick'); expect(parts.name).toEqual('_onclick');
expect(parts.memberof).toEqual('Button'); expect(parts.memberof).toEqual('Button');
expect(parts.scopePunc).toEqual('~'); expect(parts.scope).toEqual('~');
}); });
it('should work on global names', function() { it('should work on global names', function() {
@ -133,7 +133,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('close'); expect(parts.name).toEqual('close');
expect(parts.memberof).toEqual(''); expect(parts.memberof).toEqual('');
expect(parts.scopePunc).toEqual(''); expect(parts.scope).toEqual('');
}); });
it('should work when a single property uses bracket notation', function() { it('should work when a single property uses bracket notation', function() {
@ -142,7 +142,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('open'); expect(parts.name).toEqual('open');
expect(parts.memberof).toEqual('channels."#ops"'); expect(parts.memberof).toEqual('channels."#ops"');
expect(parts.scopePunc).toEqual('#'); expect(parts.scope).toEqual('#');
}); });
it('should work when consecutive properties use bracket notation', function() { it('should work when consecutive properties use bracket notation', function() {
@ -151,7 +151,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('"log.max"'); expect(parts.name).toEqual('"log.max"');
expect(parts.memberof).toEqual('channels."#bots"'); expect(parts.memberof).toEqual('channels."#bots"');
expect(parts.scopePunc).toEqual('.'); expect(parts.scope).toEqual('.');
}); });
it('should work when a property uses single-quoted bracket notation', function() { it('should work when a property uses single-quoted bracket notation', function() {
@ -160,7 +160,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toBe("'#ops'"); expect(parts.name).toBe("'#ops'");
expect(parts.memberof).toBe('channels'); expect(parts.memberof).toBe('channels');
expect(parts.scopePunc).toBe('.'); expect(parts.scope).toBe('.');
}); });
it('should work on double-quoted strings', function() { it('should work on double-quoted strings', function() {
@ -170,7 +170,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('"foo.bar"'); expect(parts.name).toEqual('"foo.bar"');
expect(parts.longname).toEqual('"foo.bar"'); expect(parts.longname).toEqual('"foo.bar"');
expect(parts.memberof).toEqual(''); expect(parts.memberof).toEqual('');
expect(parts.scopePunc).toEqual(''); expect(parts.scope).toEqual('');
}); });
it('should work on single-quoted strings', function() { it('should work on single-quoted strings', function() {
@ -180,7 +180,7 @@ describe('jsdoc/name', function() {
expect(parts.name).toBe("'foo.bar'"); expect(parts.name).toBe("'foo.bar'");
expect(parts.longname).toBe("'foo.bar'"); expect(parts.longname).toBe("'foo.bar'");
expect(parts.memberof).toBe(''); expect(parts.memberof).toBe('');
expect(parts.scopePunc).toBe(''); expect(parts.scope).toBe('');
}); });
it('should find the variation', function() { it('should find the variation', function() {
@ -191,17 +191,6 @@ describe('jsdoc/name', function() {
expect(parts.name).toEqual('fadein'); expect(parts.name).toEqual('fadein');
expect(parts.longname).toEqual('anim.fadein(2)'); expect(parts.longname).toEqual('anim.fadein(2)');
}); });
it('should have a deprecated "scope" property that matches the "scopePunc" property', function() {
var parts;
spyOn(console, 'error');
parts = jsdoc.name.shorten('ClassA#instanceMethod');
expect(parts.scope).toBeDefined();
expect(parts.scope).toBe(parts.scopePunc);
expect(console.error).toHaveBeenCalled();
});
}); });
describe('applyNamespace', function() { describe('applyNamespace', function() {