Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
+14
-14
@@ -17,7 +17,7 @@ import EventType from '../events/EventType.js';
|
||||
* @template T
|
||||
* @param {number=} opt_highWaterMark High water mark.
|
||||
*/
|
||||
var LRUCache = function(opt_highWaterMark) {
|
||||
const LRUCache = function(opt_highWaterMark) {
|
||||
|
||||
EventTarget.call(this);
|
||||
|
||||
@@ -93,7 +93,7 @@ LRUCache.prototype.containsKey = function(key) {
|
||||
* @template S
|
||||
*/
|
||||
LRUCache.prototype.forEach = function(f, opt_this) {
|
||||
var entry = this.oldest_;
|
||||
let entry = this.oldest_;
|
||||
while (entry) {
|
||||
f.call(opt_this, entry.value_, entry.key_, this);
|
||||
entry = entry.newer;
|
||||
@@ -106,9 +106,9 @@ LRUCache.prototype.forEach = function(f, opt_this) {
|
||||
* @return {T} Value.
|
||||
*/
|
||||
LRUCache.prototype.get = function(key) {
|
||||
var entry = this.entries_[key];
|
||||
const entry = this.entries_[key];
|
||||
assert(entry !== undefined,
|
||||
15); // Tried to get a value for a key that does not exist in the cache
|
||||
15); // Tried to get a value for a key that does not exist in the cache
|
||||
if (entry === this.newest_) {
|
||||
return entry.value_;
|
||||
} else if (entry === this.oldest_) {
|
||||
@@ -132,7 +132,7 @@ LRUCache.prototype.get = function(key) {
|
||||
* @return {T} The removed entry.
|
||||
*/
|
||||
LRUCache.prototype.remove = function(key) {
|
||||
var entry = this.entries_[key];
|
||||
const entry = this.entries_[key];
|
||||
assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache
|
||||
if (entry === this.newest_) {
|
||||
this.newest_ = /** @type {ol.LRUCacheEntry} */ (entry.older);
|
||||
@@ -166,9 +166,9 @@ LRUCache.prototype.getCount = function() {
|
||||
* @return {Array.<string>} Keys.
|
||||
*/
|
||||
LRUCache.prototype.getKeys = function() {
|
||||
var keys = new Array(this.count_);
|
||||
var i = 0;
|
||||
var entry;
|
||||
const keys = new Array(this.count_);
|
||||
let i = 0;
|
||||
let entry;
|
||||
for (entry = this.newest_; entry; entry = entry.older) {
|
||||
keys[i++] = entry.key_;
|
||||
}
|
||||
@@ -180,9 +180,9 @@ LRUCache.prototype.getKeys = function() {
|
||||
* @return {Array.<T>} Values.
|
||||
*/
|
||||
LRUCache.prototype.getValues = function() {
|
||||
var values = new Array(this.count_);
|
||||
var i = 0;
|
||||
var entry;
|
||||
const values = new Array(this.count_);
|
||||
let i = 0;
|
||||
let entry;
|
||||
for (entry = this.newest_; entry; entry = entry.older) {
|
||||
values[i++] = entry.value_;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ LRUCache.prototype.peekFirstKey = function() {
|
||||
* @return {T} value Value.
|
||||
*/
|
||||
LRUCache.prototype.pop = function() {
|
||||
var entry = this.oldest_;
|
||||
const entry = this.oldest_;
|
||||
delete this.entries_[entry.key_];
|
||||
if (entry.newer) {
|
||||
entry.newer.older = null;
|
||||
@@ -249,8 +249,8 @@ LRUCache.prototype.replace = function(key, value) {
|
||||
*/
|
||||
LRUCache.prototype.set = function(key, value) {
|
||||
assert(!(key in this.entries_),
|
||||
16); // Tried to set a value for a key that is used already
|
||||
var entry = /** @type {ol.LRUCacheEntry} */ ({
|
||||
16); // Tried to set a value for a key that is used already
|
||||
const entry = /** @type {ol.LRUCacheEntry} */ ({
|
||||
key_: key,
|
||||
newer: null,
|
||||
older: this.newest_,
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* @param {boolean=} opt_circular The last item is connected to the first one,
|
||||
* and the first item to the last one. Default is true.
|
||||
*/
|
||||
var LinkedList = function(opt_circular) {
|
||||
const LinkedList = function(opt_circular) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -51,13 +51,13 @@ var LinkedList = function(opt_circular) {
|
||||
LinkedList.prototype.insertItem = function(data) {
|
||||
|
||||
/** @type {ol.LinkedListItem} */
|
||||
var item = {
|
||||
const item = {
|
||||
prev: undefined,
|
||||
next: undefined,
|
||||
data: data
|
||||
};
|
||||
|
||||
var head = this.head_;
|
||||
const head = this.head_;
|
||||
|
||||
//Initialize the list.
|
||||
if (!head) {
|
||||
@@ -69,7 +69,7 @@ LinkedList.prototype.insertItem = function(data) {
|
||||
}
|
||||
} else {
|
||||
//Link the new item to the adjacent ones.
|
||||
var next = head.next;
|
||||
const next = head.next;
|
||||
item.prev = head;
|
||||
item.next = next;
|
||||
head.next = item;
|
||||
@@ -90,10 +90,10 @@ LinkedList.prototype.insertItem = function(data) {
|
||||
* if possible.
|
||||
*/
|
||||
LinkedList.prototype.removeItem = function() {
|
||||
var head = this.head_;
|
||||
const head = this.head_;
|
||||
if (head) {
|
||||
var next = head.next;
|
||||
var prev = head.prev;
|
||||
const next = head.next;
|
||||
const prev = head.prev;
|
||||
if (next) {
|
||||
next.prev = prev;
|
||||
}
|
||||
@@ -221,7 +221,7 @@ LinkedList.prototype.setFirstItem = function() {
|
||||
LinkedList.prototype.concat = function(list) {
|
||||
if (list.head_) {
|
||||
if (this.head_) {
|
||||
var end = this.head_.next;
|
||||
const end = this.head_.next;
|
||||
this.head_.next = list.first_;
|
||||
list.first_.prev = this.head_;
|
||||
end.prev = list.last_;
|
||||
|
||||
@@ -19,7 +19,7 @@ import _ol_obj_ from '../obj.js';
|
||||
* @struct
|
||||
* @template T
|
||||
*/
|
||||
var PriorityQueue = function(priorityFunction, keyFunction) {
|
||||
const PriorityQueue = function(priorityFunction, keyFunction) {
|
||||
|
||||
/**
|
||||
* @type {function(T): number}
|
||||
@@ -76,9 +76,9 @@ PriorityQueue.prototype.clear = function() {
|
||||
* @return {T} Element.
|
||||
*/
|
||||
PriorityQueue.prototype.dequeue = function() {
|
||||
var elements = this.elements_;
|
||||
var priorities = this.priorities_;
|
||||
var element = elements[0];
|
||||
const elements = this.elements_;
|
||||
const priorities = this.priorities_;
|
||||
const element = elements[0];
|
||||
if (elements.length == 1) {
|
||||
elements.length = 0;
|
||||
priorities.length = 0;
|
||||
@@ -87,7 +87,7 @@ PriorityQueue.prototype.dequeue = function() {
|
||||
priorities[0] = priorities.pop();
|
||||
this.siftUp_(0);
|
||||
}
|
||||
var elementKey = this.keyFunction_(element);
|
||||
const elementKey = this.keyFunction_(element);
|
||||
delete this.queuedElements_[elementKey];
|
||||
return element;
|
||||
};
|
||||
@@ -100,8 +100,8 @@ PriorityQueue.prototype.dequeue = function() {
|
||||
*/
|
||||
PriorityQueue.prototype.enqueue = function(element) {
|
||||
assert(!(this.keyFunction_(element) in this.queuedElements_),
|
||||
31); // Tried to enqueue an `element` that was already added to the queue
|
||||
var priority = this.priorityFunction_(element);
|
||||
31); // Tried to enqueue an `element` that was already added to the queue
|
||||
const priority = this.priorityFunction_(element);
|
||||
if (priority != PriorityQueue.DROP) {
|
||||
this.elements_.push(element);
|
||||
this.priorities_.push(priority);
|
||||
@@ -159,7 +159,7 @@ PriorityQueue.prototype.getParentIndex_ = function(index) {
|
||||
* @private
|
||||
*/
|
||||
PriorityQueue.prototype.heapify_ = function() {
|
||||
var i;
|
||||
let i;
|
||||
for (i = (this.elements_.length >> 1) - 1; i >= 0; i--) {
|
||||
this.siftUp_(i);
|
||||
}
|
||||
@@ -197,18 +197,18 @@ PriorityQueue.prototype.isQueued = function(element) {
|
||||
* @private
|
||||
*/
|
||||
PriorityQueue.prototype.siftUp_ = function(index) {
|
||||
var elements = this.elements_;
|
||||
var priorities = this.priorities_;
|
||||
var count = elements.length;
|
||||
var element = elements[index];
|
||||
var priority = priorities[index];
|
||||
var startIndex = index;
|
||||
const elements = this.elements_;
|
||||
const priorities = this.priorities_;
|
||||
const count = elements.length;
|
||||
const element = elements[index];
|
||||
const priority = priorities[index];
|
||||
const startIndex = index;
|
||||
|
||||
while (index < (count >> 1)) {
|
||||
var lIndex = this.getLeftChildIndex_(index);
|
||||
var rIndex = this.getRightChildIndex_(index);
|
||||
const lIndex = this.getLeftChildIndex_(index);
|
||||
const rIndex = this.getRightChildIndex_(index);
|
||||
|
||||
var smallerChildIndex = rIndex < count &&
|
||||
const smallerChildIndex = rIndex < count &&
|
||||
priorities[rIndex] < priorities[lIndex] ?
|
||||
rIndex : lIndex;
|
||||
|
||||
@@ -229,13 +229,13 @@ PriorityQueue.prototype.siftUp_ = function(index) {
|
||||
* @private
|
||||
*/
|
||||
PriorityQueue.prototype.siftDown_ = function(startIndex, index) {
|
||||
var elements = this.elements_;
|
||||
var priorities = this.priorities_;
|
||||
var element = elements[index];
|
||||
var priority = priorities[index];
|
||||
const elements = this.elements_;
|
||||
const priorities = this.priorities_;
|
||||
const element = elements[index];
|
||||
const priority = priorities[index];
|
||||
|
||||
while (index > startIndex) {
|
||||
var parentIndex = this.getParentIndex_(index);
|
||||
const parentIndex = this.getParentIndex_(index);
|
||||
if (priorities[parentIndex] > priority) {
|
||||
elements[index] = elements[parentIndex];
|
||||
priorities[index] = priorities[parentIndex];
|
||||
@@ -253,12 +253,12 @@ PriorityQueue.prototype.siftDown_ = function(startIndex, index) {
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
PriorityQueue.prototype.reprioritize = function() {
|
||||
var priorityFunction = this.priorityFunction_;
|
||||
var elements = this.elements_;
|
||||
var priorities = this.priorities_;
|
||||
var index = 0;
|
||||
var n = elements.length;
|
||||
var element, i, priority;
|
||||
const priorityFunction = this.priorityFunction_;
|
||||
const elements = this.elements_;
|
||||
const priorities = this.priorities_;
|
||||
let index = 0;
|
||||
const n = elements.length;
|
||||
let element, i, priority;
|
||||
for (i = 0; i < n; ++i) {
|
||||
element = elements[i];
|
||||
priority = priorityFunction(element);
|
||||
|
||||
+18
-18
@@ -15,7 +15,7 @@ import _ol_obj_ from '../obj.js';
|
||||
* @struct
|
||||
* @template T
|
||||
*/
|
||||
var RBush = function(opt_maxEntries) {
|
||||
const RBush = function(opt_maxEntries) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -40,7 +40,7 @@ var RBush = function(opt_maxEntries) {
|
||||
*/
|
||||
RBush.prototype.insert = function(extent, value) {
|
||||
/** @type {ol.RBushEntry} */
|
||||
var item = {
|
||||
const item = {
|
||||
minX: extent[0],
|
||||
minY: extent[1],
|
||||
maxX: extent[2],
|
||||
@@ -59,13 +59,13 @@ RBush.prototype.insert = function(extent, value) {
|
||||
* @param {Array.<T>} values Values.
|
||||
*/
|
||||
RBush.prototype.load = function(extents, values) {
|
||||
var items = new Array(values.length);
|
||||
for (var i = 0, l = values.length; i < l; i++) {
|
||||
var extent = extents[i];
|
||||
var value = values[i];
|
||||
const items = new Array(values.length);
|
||||
for (let i = 0, l = values.length; i < l; i++) {
|
||||
const extent = extents[i];
|
||||
const value = values[i];
|
||||
|
||||
/** @type {ol.RBushEntry} */
|
||||
var item = {
|
||||
const item = {
|
||||
minX: extent[0],
|
||||
minY: extent[1],
|
||||
maxX: extent[2],
|
||||
@@ -85,11 +85,11 @@ RBush.prototype.load = function(extents, values) {
|
||||
* @return {boolean} Removed.
|
||||
*/
|
||||
RBush.prototype.remove = function(value) {
|
||||
var uid = getUid(value);
|
||||
const uid = getUid(value);
|
||||
|
||||
// get the object in which the value was wrapped when adding to the
|
||||
// internal rbush. then use that object to do the removal.
|
||||
var item = this.items_[uid];
|
||||
const item = this.items_[uid];
|
||||
delete this.items_[uid];
|
||||
return this.rbush_.remove(item) !== null;
|
||||
};
|
||||
@@ -101,8 +101,8 @@ RBush.prototype.remove = function(value) {
|
||||
* @param {T} value Value.
|
||||
*/
|
||||
RBush.prototype.update = function(extent, value) {
|
||||
var item = this.items_[getUid(value)];
|
||||
var bbox = [item.minX, item.minY, item.maxX, item.maxY];
|
||||
const item = this.items_[getUid(value)];
|
||||
const bbox = [item.minX, item.minY, item.maxX, item.maxY];
|
||||
if (!equals(bbox, extent)) {
|
||||
this.remove(value);
|
||||
this.insert(extent, value);
|
||||
@@ -115,7 +115,7 @@ RBush.prototype.update = function(extent, value) {
|
||||
* @return {Array.<T>} All.
|
||||
*/
|
||||
RBush.prototype.getAll = function() {
|
||||
var items = this.rbush_.all();
|
||||
const items = this.rbush_.all();
|
||||
return items.map(function(item) {
|
||||
return item.value;
|
||||
});
|
||||
@@ -129,13 +129,13 @@ RBush.prototype.getAll = function() {
|
||||
*/
|
||||
RBush.prototype.getInExtent = function(extent) {
|
||||
/** @type {ol.RBushEntry} */
|
||||
var bbox = {
|
||||
const bbox = {
|
||||
minX: extent[0],
|
||||
minY: extent[1],
|
||||
maxX: extent[2],
|
||||
maxY: extent[3]
|
||||
};
|
||||
var items = this.rbush_.search(bbox);
|
||||
const items = this.rbush_.search(bbox);
|
||||
return items.map(function(item) {
|
||||
return item.value;
|
||||
});
|
||||
@@ -178,8 +178,8 @@ RBush.prototype.forEachInExtent = function(extent, callback, opt_this) {
|
||||
* @template S
|
||||
*/
|
||||
RBush.prototype.forEach_ = function(values, callback, opt_this) {
|
||||
var result;
|
||||
for (var i = 0, l = values.length; i < l; i++) {
|
||||
let result;
|
||||
for (let i = 0, l = values.length; i < l; i++) {
|
||||
result = callback.call(opt_this, values[i]);
|
||||
if (result) {
|
||||
return result;
|
||||
@@ -212,7 +212,7 @@ RBush.prototype.clear = function() {
|
||||
*/
|
||||
RBush.prototype.getExtent = function(opt_extent) {
|
||||
// FIXME add getExtent() to rbush
|
||||
var data = this.rbush_.data;
|
||||
const data = this.rbush_.data;
|
||||
return createOrUpdate(data.minX, data.minY, data.maxX, data.maxY, opt_extent);
|
||||
};
|
||||
|
||||
@@ -222,7 +222,7 @@ RBush.prototype.getExtent = function(opt_extent) {
|
||||
*/
|
||||
RBush.prototype.concat = function(rbush) {
|
||||
this.rbush_.load(rbush.rbush_.all());
|
||||
for (var i in rbush.items_) {
|
||||
for (const i in rbush.items_) {
|
||||
this.items_[i | 0] = rbush.items_[i | 0];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user