mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
remove unused code
This commit is contained in:
parent
c510b336d2
commit
d28d15eb72
@ -8,10 +8,6 @@ var util = require('util');
|
||||
// Counter for generating unique node IDs.
|
||||
var uid = 100000000;
|
||||
|
||||
// TODO: docs
|
||||
// TODO: currently unused
|
||||
var GLOBAL_NODE_ID = exports.GLOBAL_NODE_ID = require('jsdoc/name').LONGNAMES.GLOBAL;
|
||||
|
||||
/**
|
||||
* Check whether an AST node represents a function.
|
||||
*
|
||||
@ -66,30 +62,6 @@ var addNodeProperties = exports.addNodeProperties = function(node) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!node.knownVariables) {
|
||||
newProperties.knownVariables = {
|
||||
value: node.enclosingScope ? doop(node.enclosingScope.knownVariables) : {}
|
||||
};
|
||||
}
|
||||
|
||||
if (!node.ownedVariables) {
|
||||
newProperties.ownedVariables = {
|
||||
value: {}
|
||||
};
|
||||
}
|
||||
|
||||
if (!node.knownAliases) {
|
||||
newProperties.knownAliases = {
|
||||
value: node.enclosingScope ? doop(node.enclosingScope.knownAliases) : {}
|
||||
};
|
||||
}
|
||||
|
||||
if (!node.ownedAliases) {
|
||||
newProperties.ownedAliases = {
|
||||
value: {}
|
||||
};
|
||||
}
|
||||
|
||||
if (debugEnabled && !node.parentId) {
|
||||
newProperties.parentId = {
|
||||
enumerable: true,
|
||||
@ -113,21 +85,6 @@ var addNodeProperties = exports.addNodeProperties = function(node) {
|
||||
return node;
|
||||
};
|
||||
|
||||
// TODO: docs
|
||||
// TODO: currently unused
|
||||
exports.makeGlobalNode = function() {
|
||||
var node = {
|
||||
name: GLOBAL_NODE_ID,
|
||||
type: GLOBAL_NODE_ID
|
||||
};
|
||||
|
||||
Object.defineProperty(node, 'nodeId', {
|
||||
value: GLOBAL_NODE_ID
|
||||
});
|
||||
|
||||
return addNodeProperties(node);
|
||||
};
|
||||
|
||||
// TODO: docs
|
||||
var nodeToString = exports.nodeToString = function(node) {
|
||||
var tempObject;
|
||||
@ -341,56 +298,3 @@ var getInfo = exports.getInfo = function(node) {
|
||||
|
||||
return info;
|
||||
};
|
||||
|
||||
// TODO: may want to use separate methods for known and owned variables/functions/aliases
|
||||
|
||||
// TODO: docs
|
||||
function _addVariable(node, name, value) {
|
||||
node.knownVariables[name] = node.ownedVariables[name] = value;
|
||||
}
|
||||
|
||||
// TODO: docs
|
||||
var addVariable = exports.addVariable = function(node, declarator) {
|
||||
var name = declarator.id.name;
|
||||
var value = (declarator.init || null);
|
||||
_addVariable(node, name, value);
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
// TODO: docs
|
||||
var addAllVariables = exports.addAllVariables = function(node, declaration) {
|
||||
for (var i = 0, l = declaration.declarations.length; i < l; i++) {
|
||||
addVariable(node, declaration.declarations[i]);
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
// TODO: docs
|
||||
var addFunction = exports.addFunction = function(node, declaration) {
|
||||
// TODO: should we store these separately, since they're hoisted above variable declarations?
|
||||
// right now we appear to give functions and variables equal precedence, which is wrong
|
||||
|
||||
// don't add anonymous functions
|
||||
if (declaration.id) {
|
||||
_addVariable(node, declaration.id.name, null);
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
// TODO: docs
|
||||
var addAlias = exports.addAlias = function(node, variableName, aliasName) {
|
||||
[node.knownAliases, node.ownedAliases].forEach(function(target) {
|
||||
if ( !Array.isArray(target[aliasName]) ) {
|
||||
target[aliasName] = [];
|
||||
}
|
||||
|
||||
if (target[aliasName].indexOf(variableName) === -1) {
|
||||
target[aliasName].push(variableName);
|
||||
}
|
||||
});
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
@ -34,22 +34,6 @@ var PARSERS = exports.PARSERS = {
|
||||
rhino: 'rhino/jsdoc/src/parser'
|
||||
};
|
||||
|
||||
// TODO: docs
|
||||
// TODO: not currently used
|
||||
function makeGlobalDoclet(globalScope) {
|
||||
var doclet = new jsdoc.doclet.Doclet('/** Auto-generated doclet for global scope */', {});
|
||||
|
||||
if (globalScope) {
|
||||
// TODO: handle global aliases
|
||||
Object.keys(globalScope.ownedVariables).forEach(function(variable) {
|
||||
doclet.meta.vars = doclet.meta.vars || {};
|
||||
doclet.meta.vars[variable] = null;
|
||||
});
|
||||
}
|
||||
|
||||
return doclet;
|
||||
}
|
||||
|
||||
// TODO: docs
|
||||
exports.createParser = function(type) {
|
||||
|
||||
@ -114,8 +98,8 @@ util.inherits(Parser, events.EventEmitter);
|
||||
Parser.prototype.clear = function() {
|
||||
this._resultBuffer = [];
|
||||
this.refs = {};
|
||||
this.refs[jsdoc.src.astnode.GLOBAL_NODE_ID] = {};
|
||||
this.refs[jsdoc.src.astnode.GLOBAL_NODE_ID].meta = {};
|
||||
this.refs[jsdoc.name.LONGNAMES.GLOBAL] = {};
|
||||
this.refs[jsdoc.name.LONGNAMES.GLOBAL].meta = {};
|
||||
};
|
||||
|
||||
// TODO: update docs
|
||||
@ -353,7 +337,7 @@ Parser.prototype.astnodeToMemberof = function(node) {
|
||||
}
|
||||
|
||||
// do we know that it's a global?
|
||||
doclet = this.refs[jsdoc.src.astnode.GLOBAL_NODE_ID];
|
||||
doclet = this.refs[jsdoc.name.LONGNAMES.GLOBAL];
|
||||
if ( doclet && definedInScope(doclet, basename) ) {
|
||||
result = [doclet.meta.vars[basename], basename];
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
var jsdoc = {
|
||||
doclet: require('jsdoc/doclet'),
|
||||
name: require('jsdoc/name'),
|
||||
src: {
|
||||
astnode: require('jsdoc/src/astnode'),
|
||||
syntax: require('jsdoc/src/syntax')
|
||||
@ -299,10 +300,9 @@ Visitor.prototype.visitNode = function(node, parser, filename) {
|
||||
|
||||
// TODO: docs
|
||||
// TODO: note that it's essential to call this function before you try to resolve names!
|
||||
// TODO: may be able to get rid of this using knownAliases
|
||||
function trackVars(parser, node, e) {
|
||||
var enclosingScopeId = node.enclosingScope ? node.enclosingScope.nodeId :
|
||||
jsdoc.src.astnode.GLOBAL_NODE_ID;
|
||||
jsdoc.name.LONGNAMES.GLOBAL;
|
||||
var doclet = parser.refs[enclosingScopeId];
|
||||
|
||||
if (doclet) {
|
||||
|
||||
@ -491,9 +491,9 @@ Walker.prototype._recurse = function(filename, ast) {
|
||||
|
||||
var isScope = astnode.isScope(node);
|
||||
|
||||
// for efficiency, if the node has a knownVariables property, assume that we've already
|
||||
// for efficiency, if the node has a `parent` property, assume that we've already
|
||||
// added the required properties
|
||||
if (!node.knownVariables) {
|
||||
if (typeof node.parent !== 'undefined') {
|
||||
astnode.addNodeProperties(node);
|
||||
}
|
||||
|
||||
|
||||
@ -48,41 +48,16 @@ describe('jsdoc/src/astnode', function() {
|
||||
expect(typeof astnode).toBe('object');
|
||||
});
|
||||
|
||||
it('should export a GLOBAL_NODE_ID property', function() {
|
||||
expect(astnode.GLOBAL_NODE_ID).toBeDefined();
|
||||
expect(typeof astnode.GLOBAL_NODE_ID).toBe('string');
|
||||
});
|
||||
|
||||
it('should export a nodeToString method', function() {
|
||||
expect(astnode.nodeToString).toBeDefined();
|
||||
expect(typeof astnode.nodeToString).toBe('function');
|
||||
});
|
||||
|
||||
it('should export an addAlias method', function() {
|
||||
expect(astnode.addAlias).toBeDefined();
|
||||
expect(typeof astnode.addAlias).toBe('function');
|
||||
});
|
||||
|
||||
it('should export an addAllVariables method', function() {
|
||||
expect(astnode.addAllVariables).toBeDefined();
|
||||
expect(typeof astnode.addAllVariables).toBe('function');
|
||||
});
|
||||
|
||||
it('should export an addFunction method', function() {
|
||||
expect(astnode.addFunction).toBeDefined();
|
||||
expect(typeof astnode.addFunction).toBe('function');
|
||||
});
|
||||
|
||||
it('should export an addNodeProperties method', function() {
|
||||
expect(astnode.addNodeProperties).toBeDefined();
|
||||
expect(typeof astnode.addNodeProperties).toBe('function');
|
||||
});
|
||||
|
||||
it('should export an addVariable method', function() {
|
||||
expect(astnode.addVariable).toBeDefined();
|
||||
expect(typeof astnode.addVariable).toBe('function');
|
||||
});
|
||||
|
||||
it('should export a getInfo method', function() {
|
||||
expect(astnode.getInfo).toBeDefined();
|
||||
expect(typeof astnode.getInfo).toBe('function');
|
||||
@ -108,145 +83,6 @@ describe('jsdoc/src/astnode', function() {
|
||||
expect(typeof astnode.isScope).toBe('function');
|
||||
});
|
||||
|
||||
it('should export a makeGlobalNode method', function() {
|
||||
expect(astnode.makeGlobalNode).toBeDefined();
|
||||
expect(typeof astnode.makeGlobalNode).toBe('function');
|
||||
});
|
||||
|
||||
describe('addAlias', function() {
|
||||
it('should throw an error when given bad input', function() {
|
||||
function noParams() {
|
||||
astnode.addAlias();
|
||||
}
|
||||
|
||||
function noNode() {
|
||||
astnode.addAlias(null, 'bar', 'foo');
|
||||
}
|
||||
|
||||
expect(noParams).toThrow();
|
||||
expect(noNode).toThrow();
|
||||
});
|
||||
|
||||
it('should add the specified variable name as a known and owned alias', function() {
|
||||
var aliasName = 'bar';
|
||||
var variableName = 'foo';
|
||||
var node = astnode.addAlias(astnode.addNodeProperties({}), variableName, aliasName);
|
||||
|
||||
[node.knownAliases[aliasName], node.ownedAliases[aliasName]].forEach(function(arr) {
|
||||
expect(arr).toBeDefined();
|
||||
expect(arr.length).toBe(1);
|
||||
expect( arr.indexOf(variableName) ).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not add aliases that are already defined', function() {
|
||||
var aliasName1 = 'bar';
|
||||
var aliasName2 = aliasName1;
|
||||
var variableName = 'foo';
|
||||
var node = astnode.addAlias(astnode.addNodeProperties({}), variableName, aliasName1);
|
||||
node = astnode.addAlias(node, variableName, aliasName2);
|
||||
|
||||
[node.knownAliases[aliasName1], node.ownedAliases[aliasName1]].forEach(function(arr) {
|
||||
expect(arr).toBeDefined();
|
||||
expect(arr.length).toBe(1);
|
||||
expect( arr.indexOf(variableName) ).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('addAllVariables', function() {
|
||||
it('should throw an error when given bad input', function() {
|
||||
function noParams() {
|
||||
astnode.addAllVariables();
|
||||
}
|
||||
|
||||
function noDeclarations() {
|
||||
astnode.addAllVariables({});
|
||||
}
|
||||
|
||||
expect(noParams).toThrow();
|
||||
expect(noDeclarations).toThrow();
|
||||
});
|
||||
|
||||
it('should return the node', function() {
|
||||
var node = astnode.addNodeProperties({foo: 1});
|
||||
node = astnode.addAllVariables(node, variableDeclaration1);
|
||||
|
||||
expect(node).toBeDefined();
|
||||
expect(node.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a declaration with one declarator to the known/owned variables', function() {
|
||||
var node = astnode.addNodeProperties( doop(functionDeclaration1) );
|
||||
node = astnode.addAllVariables(node, variableDeclaration1);
|
||||
|
||||
expect(node.knownVariables).toBeDefined();
|
||||
expect(typeof node.knownVariables.foo).toBe('object');
|
||||
expect(node.knownVariables.foo.value).toBe(1);
|
||||
|
||||
expect(node.ownedVariables.foo).toBeDefined();
|
||||
expect(node.ownedVariables.foo).toBe(node.knownVariables.foo);
|
||||
});
|
||||
|
||||
it('should add a declaration with multiple declarators to the known/owned variables',
|
||||
function() {
|
||||
var node = astnode.addNodeProperties( doop(functionDeclaration1) );
|
||||
node = astnode.addAllVariables(node, variableDeclaration2);
|
||||
|
||||
expect(node.knownVariables).toBeDefined();
|
||||
expect(typeof node.knownVariables.foo).toBe('object');
|
||||
expect(node.knownVariables.foo.value).toBe(1);
|
||||
|
||||
expect(typeof node.knownVariables.bar).toBe('object');
|
||||
expect(node.knownVariables.bar.value).toBe(2);
|
||||
|
||||
expect(node.ownedVariables.foo).toBeDefined();
|
||||
expect(node.ownedVariables.foo).toBe(node.knownVariables.foo);
|
||||
|
||||
expect(node.ownedVariables.bar).toBeDefined();
|
||||
expect(node.ownedVariables.bar).toBe(node.knownVariables.bar);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addFunction', function() {
|
||||
it('should throw an error when given bad input', function() {
|
||||
function noParams() {
|
||||
astnode.addFunction();
|
||||
}
|
||||
|
||||
function noNode() {
|
||||
astnode.addFunction(null, {id: {}});
|
||||
}
|
||||
|
||||
function noDeclaration() {
|
||||
astnode.addFunction({});
|
||||
}
|
||||
|
||||
expect(noParams).toThrow();
|
||||
expect(noNode).toThrow();
|
||||
expect(noDeclaration).toThrow();
|
||||
});
|
||||
|
||||
it('should return the node', function() {
|
||||
var node = astnode.addNodeProperties({foo: 1});
|
||||
node = astnode.addFunction(node, {id: {name: 'bar'}});
|
||||
|
||||
expect(node).toBeDefined();
|
||||
expect(node.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a function declaration to the known/owned variables', function() {
|
||||
var node = astnode.addNodeProperties( doop(functionDeclaration1) );
|
||||
node = astnode.addFunction(node, functionDeclaration1a);
|
||||
|
||||
expect(node.knownVariables.bar).toBeDefined();
|
||||
expect(node.knownVariables.bar).toBe(null);
|
||||
|
||||
expect(node.ownedVariables.bar).toBeDefined();
|
||||
expect(node.ownedVariables.bar).toBe(node.knownVariables.bar);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addNodeProperties', function() {
|
||||
var debugEnabled;
|
||||
|
||||
@ -418,103 +254,6 @@ describe('jsdoc/src/astnode', function() {
|
||||
expect(node.enclosingScopeId).toBe(enclosingScope.nodeId);
|
||||
});
|
||||
|
||||
it('should add a non-enumerable knownVariables property', function() {
|
||||
var node = astnode.addNodeProperties({});
|
||||
var descriptor = Object.getOwnPropertyDescriptor(node, 'knownVariables');
|
||||
|
||||
expect(descriptor).toBeDefined();
|
||||
expect(typeof descriptor.value).toBe('object');
|
||||
expect(Object.keys(descriptor.value).length).toBe(0);
|
||||
expect(descriptor.enumerable).toBe(false);
|
||||
});
|
||||
|
||||
it('should copy known variables from the enclosing scope', function() {
|
||||
var enclosingScope = {knownVariables: {foo: 1}};
|
||||
var node = astnode.addNodeProperties({enclosingScope: enclosingScope});
|
||||
|
||||
expect(Object.keys(node.knownVariables).length).toBe(1);
|
||||
expect(node.knownVariables.foo).toBeDefined();
|
||||
expect(node.knownVariables.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a non-enumerable ownedVariables property', function() {
|
||||
var node = astnode.addNodeProperties({});
|
||||
var descriptor = Object.getOwnPropertyDescriptor(node, 'ownedVariables');
|
||||
|
||||
expect(descriptor).toBeDefined();
|
||||
expect(typeof descriptor.value).toBe('object');
|
||||
expect(Object.keys(descriptor.value).length).toBe(0);
|
||||
expect(descriptor.enumerable).toBe(false);
|
||||
});
|
||||
|
||||
it('should add a non-enumerable knownAliases property', function() {
|
||||
var node = astnode.addNodeProperties({});
|
||||
var descriptor = Object.getOwnPropertyDescriptor(node, 'knownAliases');
|
||||
|
||||
expect(descriptor).toBeDefined();
|
||||
expect(typeof descriptor.value).toBe('object');
|
||||
expect(Object.keys(descriptor.value).length).toBe(0);
|
||||
expect(descriptor.enumerable).toBe(false);
|
||||
});
|
||||
|
||||
it('should copy known aliases from the enclosing scope', function() {
|
||||
var enclosingScope = {knownAliases: {foo: []}};
|
||||
var node = astnode.addNodeProperties({enclosingScope: enclosingScope});
|
||||
|
||||
expect(Object.keys(node.knownAliases).length).toBe(1);
|
||||
expect(node.knownAliases.foo).toBeDefined();
|
||||
expect( Array.isArray(node.knownAliases.foo) ).toBe(true);
|
||||
});
|
||||
|
||||
it('should add a non-enumerable ownedAliases property', function() {
|
||||
var node = astnode.addNodeProperties({});
|
||||
var descriptor = Object.getOwnPropertyDescriptor(node, 'ownedAliases');
|
||||
|
||||
expect(descriptor).toBeDefined();
|
||||
expect(typeof descriptor.value).toBe('object');
|
||||
expect(Object.keys(descriptor.value).length).toBe(0);
|
||||
expect(descriptor.enumerable).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addVariable', function() {
|
||||
it('should throw an error when given bad input', function() {
|
||||
function noParams() {
|
||||
astnode.addVariable();
|
||||
}
|
||||
|
||||
function noNode() {
|
||||
astnode.addVariable(null, {id: {}});
|
||||
}
|
||||
|
||||
function noDeclarations() {
|
||||
astnode.addVariable({});
|
||||
}
|
||||
|
||||
expect(noParams).toThrow();
|
||||
expect(noNode).toThrow();
|
||||
expect(noDeclarations).toThrow();
|
||||
});
|
||||
|
||||
it('should return the node', function() {
|
||||
var node = astnode.addNodeProperties({foo: 1});
|
||||
node = astnode.addVariable(node, {id: {name: 'bar'}});
|
||||
|
||||
expect(node).toBeDefined();
|
||||
expect(node.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a declarator to the known/owned variables', function() {
|
||||
var node = astnode.addNodeProperties( doop(functionDeclaration1) );
|
||||
node = astnode.addVariable(node, variableDeclarator1);
|
||||
|
||||
expect(node.knownVariables.foo).toBeDefined();
|
||||
expect(typeof node.knownVariables.foo).toBe('object');
|
||||
expect(node.knownVariables.foo.value).toBe(1);
|
||||
|
||||
expect(node.ownedVariables.foo).toBeDefined();
|
||||
expect(node.ownedVariables.foo).toBe(node.knownVariables.foo);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getInfo', function() {
|
||||
@ -775,24 +514,6 @@ describe('jsdoc/src/astnode', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeGlobalNode', function() {
|
||||
it('should return an object', function() {
|
||||
expect( typeof astnode.makeGlobalNode() ).toBe('object');
|
||||
});
|
||||
|
||||
it('should assign the global node ID to the nodeId, name, and type properties', function() {
|
||||
var globalNode = astnode.makeGlobalNode();
|
||||
expect(globalNode.nodeId).toBe(astnode.GLOBAL_NODE_ID);
|
||||
expect(globalNode.name).toBe(astnode.GLOBAL_NODE_ID);
|
||||
expect(globalNode.type).toBe(astnode.GLOBAL_NODE_ID);
|
||||
});
|
||||
|
||||
it('should assign nodeId as a non-enumerable property', function() {
|
||||
var keys = Object.keys( astnode.makeGlobalNode() );
|
||||
expect( keys.indexOf('nodeId') ).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nodeToString', function() {
|
||||
it('should return `[null]` for the sparse array `[,]`', function() {
|
||||
expect( astnode.nodeToString(arrayExpression) ).toBe('[null]');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user