Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused variable references #533

Merged
merged 5 commits into from Jul 1, 2014
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .jshintrc
Expand Up @@ -4,6 +4,7 @@
"laxbreak": true,
"proto": true,
"undef": true,
"unused": true,
"node": true,
"quotmark": "single",
"globals": {
Expand Down
12 changes: 6 additions & 6 deletions lib/api/attributes.js
Expand Up @@ -49,7 +49,7 @@ var setAttr = function(el, name, value) {
}
};

var attr = exports.attr = function(name, value) {
exports.attr = function(name, value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to remove all of these. Even those that are referenced are unnecessary, as we can reference exports.<name> instead. Thoughts?

// Set the value (with attr map support)
if (typeof name === 'object' || value !== undefined) {
if (typeof value === 'function') {
Expand Down Expand Up @@ -123,7 +123,7 @@ var readData = function(el, name) {
return readAll ? el.data : value;
};

var data = exports.data = function(name, value) {
exports.data = function(name, value) {
var elem = this[0];

if (!elem || !isTag(elem)) return;
Expand Down Expand Up @@ -154,7 +154,7 @@ var data = exports.data = function(name, value) {
* Get the value of an element
*/

var val = exports.val = function(value) {
exports.val = function(value) {
var querying = arguments.length === 0,
element = this[0];

Expand Down Expand Up @@ -237,15 +237,15 @@ var removeAttribute = function(elem, name) {
};


var removeAttr = exports.removeAttr = function(name) {
exports.removeAttr = function(name) {
domEach(this, function(i, elem) {
removeAttribute(elem, name);
});

return this;
};

var hasClass = exports.hasClass = function(className) {
exports.hasClass = function(className) {
return _.any(this, function(elem) {
var attrs = elem.attribs,
clazz = attrs && attrs['class'],
Expand Down Expand Up @@ -404,7 +404,7 @@ var toggleClass = exports.toggleClass = function(value, stateVal) {
return this;
};

var is = exports.is = function (selector) {
exports.is = function (selector) {
if (selector) {
return this.filter(selector).length > 0;
}
Expand Down
21 changes: 10 additions & 11 deletions lib/api/manipulation.js
Expand Up @@ -5,7 +5,6 @@ var _ = require('lodash'),
evaluate = parse.evaluate,
utils = require('../utils'),
domEach = utils.domEach,
encode = utils.encode,
slice = Array.prototype.slice;

// Create an array of nodes, recursing into arrays and parsing strings if
Expand Down Expand Up @@ -99,15 +98,15 @@ var uniqueSplice = function(array, spliceIdx, spliceCount, newElems, parent) {
return array.splice.apply(array, spliceArgs);
};

var append = exports.append = _insert(function(dom, children, parent) {
exports.append = _insert(function(dom, children, parent) {
uniqueSplice(children, children.length, 0, dom, parent);
});

var prepend = exports.prepend = _insert(function(dom, children, parent) {
exports.prepend = _insert(function(dom, children, parent) {
uniqueSplice(children, 0, 0, dom, parent);
});

var after = exports.after = function() {
exports.after = function() {
var elems = slice.call(arguments),
dom = this._makeDomArray(elems),
self = this;
Expand Down Expand Up @@ -135,7 +134,7 @@ var after = exports.after = function() {
return this;
};

var before = exports.before = function() {
exports.before = function() {
var elems = slice.call(arguments),
dom = this._makeDomArray(elems),
self = this;
Expand Down Expand Up @@ -166,7 +165,7 @@ var before = exports.before = function() {
/*
remove([selector])
*/
var remove = exports.remove = function(selector) {
exports.remove = function(selector) {
var elems = this;

// Filter if we have selector
Expand Down Expand Up @@ -198,7 +197,7 @@ var remove = exports.remove = function(selector) {
return this;
};

var replaceWith = exports.replaceWith = function(content) {
exports.replaceWith = function(content) {
var self = this;

domEach(this, function(i, el) {
Expand All @@ -225,7 +224,7 @@ var replaceWith = exports.replaceWith = function(content) {
return this;
};

var empty = exports.empty = function() {
exports.empty = function() {
domEach(this, function(i, el) {
_.each(el.children, function(el) {
el.next = el.prev = el.parent = null;
Expand All @@ -239,7 +238,7 @@ var empty = exports.empty = function() {
/**
* Set/Get the HTML
*/
var html = exports.html = function(str) {
exports.html = function(str) {
if (str === undefined) {
if (!this[0] || !this[0].children) return null;
return $.html(this[0].children, this.options);
Expand All @@ -260,7 +259,7 @@ var html = exports.html = function(str) {
return this;
};

var toString = exports.toString = function() {
exports.toString = function() {
return $.html(this);
};

Expand Down Expand Up @@ -297,7 +296,7 @@ var text = exports.text = function(str) {
return this;
};

var clone = exports.clone = function() {
exports.clone = function() {
// Turn it into HTML, then recreate it,
// Seems to be the easiest way to reconnect everything correctly
return this._make($.html(this));
Expand Down
49 changes: 24 additions & 25 deletions lib/api/traversing.js
Expand Up @@ -5,7 +5,7 @@ var _ = require('lodash'),
uniqueSort = require('htmlparser2').DomUtils.uniqueSort,
isTag = utils.isTag;

var find = exports.find = function(selector) {
exports.find = function(selector) {
var elems = _.reduce(this, function(memo, elem) {
return memo.concat(_.filter(elem.children, isTag));
}, []);
Expand All @@ -15,9 +15,8 @@ var find = exports.find = function(selector) {

// Get the parent of each element in the current set of matched elements,
// optionally filtered by a selector.
var parent = exports.parent = function(selector) {
exports.parent = function(selector) {
var set = [];
var $set;

domEach(this, function(idx, elem) {
var parentElem = elem.parent;
Expand All @@ -33,7 +32,7 @@ var parent = exports.parent = function(selector) {
return this._make(set);
};

var parents = exports.parents = function(selector) {
exports.parents = function(selector) {
var parentNodes = [];

// When multiple DOM elements are in the original set, the resulting set will
Expand All @@ -52,7 +51,7 @@ var parents = exports.parents = function(selector) {
return this._make(parentNodes);
};

var parentsUntil = exports.parentsUntil = function(selector, filter) {
exports.parentsUntil = function(selector, filter) {
var parentNodes = [], untilNode, untilNodes;

if (typeof selector === 'string') {
Expand Down Expand Up @@ -85,7 +84,7 @@ var parentsUntil = exports.parentsUntil = function(selector, filter) {
// For each element in the set, get the first element that matches the selector
// by testing the element itself and traversing up through its ancestors in the
// DOM tree.
var closest = exports.closest = function(selector) {
exports.closest = function(selector) {
var set = [];

if (!selector) {
Expand All @@ -104,7 +103,7 @@ var closest = exports.closest = function(selector) {
return this._make(set);
};

var next = exports.next = function(selector) {
exports.next = function(selector) {
if (!this[0]) { return this; }
var elems = [];

Expand All @@ -120,7 +119,7 @@ var next = exports.next = function(selector) {
return selector ? filter.call(elems, selector, this) : this._make(elems);
};

var nextAll = exports.nextAll = function(selector) {
exports.nextAll = function(selector) {
if (!this[0]) { return this; }
var elems = [];

Expand All @@ -135,7 +134,7 @@ var nextAll = exports.nextAll = function(selector) {
return selector ? filter.call(elems, selector, this) : this._make(elems);
};

var nextUntil = exports.nextUntil = function(selector, filterSelector) {
exports.nextUntil = function(selector, filterSelector) {
if (!this[0]) { return this; }
var elems = [], untilNode, untilNodes;

Expand Down Expand Up @@ -166,7 +165,7 @@ var nextUntil = exports.nextUntil = function(selector, filterSelector) {
this._make(elems);
};

var prev = exports.prev = function(selector) {
exports.prev = function(selector) {
if (!this[0]) { return this; }
var elems = [];

Expand All @@ -182,7 +181,7 @@ var prev = exports.prev = function(selector) {
return selector ? filter.call(elems, selector, this) : this._make(elems);
};

var prevAll = exports.prevAll = function(selector) {
exports.prevAll = function(selector) {
if (!this[0]) { return this; }
var elems = [];

Expand All @@ -197,7 +196,7 @@ var prevAll = exports.prevAll = function(selector) {
return selector ? filter.call(elems, selector, this) : this._make(elems);
};

var prevUntil = exports.prevUntil = function(selector, filterSelector) {
exports.prevUntil = function(selector, filterSelector) {
if (!this[0]) { return this; }
var elems = [], untilNode, untilNodes;

Expand Down Expand Up @@ -228,7 +227,7 @@ var prevUntil = exports.prevUntil = function(selector, filterSelector) {
this._make(elems);
};

var siblings = exports.siblings = function(selector) {
exports.siblings = function(selector) {
var parent = this.parent();

var elems = _.filter(
Expand All @@ -244,7 +243,7 @@ var siblings = exports.siblings = function(selector) {
}
};

var children = exports.children = function(selector) {
exports.children = function(selector) {

var elems = _.reduce(this, function(memo, elem) {
return memo.concat(_.filter(elem.children, isTag));
Expand All @@ -256,20 +255,20 @@ var children = exports.children = function(selector) {
return filter.call(elems, selector, this);
};

var contents = exports.contents = function() {
exports.contents = function() {
return this._make(_.reduce(this, function(all, elem) {
all.push.apply(all, elem.children);
return all;
}, []));
};

var each = exports.each = function(fn) {
exports.each = function(fn) {
var i = 0, len = this.length;
while (i < len && fn.call(this[i], i, this[i]) !== false) ++i;
return this;
};

var map = exports.map = function(fn) {
exports.map = function(fn) {
return this._make(_.reduce(this, function(memo, el, i) {
var val = fn.call(el, i, el);
return val == null ? memo : memo.concat(val);
Expand Down Expand Up @@ -299,16 +298,16 @@ var filter = exports.filter = function(match, container) {
return make(_.filter(this, filterFn));
};

var first = exports.first = function() {
exports.first = function() {
return this.length > 1 ? this._make(this[0]) : this;
};

var last = exports.last = function() {
exports.last = function() {
return this.length > 1 ? this._make(this[this.length - 1]) : this;
};

// Reduce the set of matched elements to the one at the specified index.
var eq = exports.eq = function(i) {
exports.eq = function(i) {
i = +i;

// Use the first identity optimization if possible
Expand All @@ -319,7 +318,7 @@ var eq = exports.eq = function(i) {
};

// Retrieve the DOM elements matched by the jQuery object.
var get = exports.get = function(i) {
exports.get = function(i) {
if (i == null) {
return Array.prototype.slice.call(this);
} else {
Expand All @@ -328,7 +327,7 @@ var get = exports.get = function(i) {
};

// Search for a given element from among the matched elements.
var index = exports.index = function(selectorOrNeedle) {
exports.index = function(selectorOrNeedle) {
var $haystack, needle;

if (arguments.length === 0) {
Expand All @@ -345,7 +344,7 @@ var index = exports.index = function(selectorOrNeedle) {
return $haystack.get().indexOf(needle);
};

var slice = exports.slice = function() {
exports.slice = function() {
return this._make([].slice.apply(this, arguments));
};

Expand All @@ -362,11 +361,11 @@ function traverseParents(self, elem, selector, limit) {

// End the most recent filtering operation in the current chain and return the
// set of matched elements to its previous state.
var end = exports.end = function() {
exports.end = function() {
return this.prevObject || this._make([]);
};

var add = exports.add = function(other, context) {
exports.add = function(other, context) {
var selection = this._make(other, context);
var contents = uniqueSort(selection.get().concat(this.get()));

Expand Down
3 changes: 1 addition & 2 deletions lib/cheerio.js
Expand Up @@ -2,8 +2,7 @@
Module dependencies
*/

var path = require('path'),
parse = require('./parse'),
var parse = require('./parse'),
_ = require('lodash');

/*
Expand Down
3 changes: 1 addition & 2 deletions lib/parse.js
@@ -1,8 +1,7 @@
/*
Module Dependencies
*/
var htmlparser = require('htmlparser2'),
utils = require('./utils');
var htmlparser = require('htmlparser2');

/*
Parser
Expand Down