Skip to content

Commit

Permalink
Replace legacy syntax for each...in with for...of
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek authored and dstillman committed Dec 21, 2016
1 parent b445283 commit 269e2f8
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion chrome/content/zotero/bindings/itembox.xml
Expand Up @@ -475,7 +475,7 @@
var popup = button.appendChild(document.createElement("menupopup"));
for each(var v in this._fieldAlternatives[fieldName]) {
for (let v of this._fieldAlternatives[fieldName]) {
var menuitem = document.createElement("menuitem");
var sv = Zotero.Utilities.ellipsize(v, 60);
menuitem.setAttribute('label', sv);
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/bindings/tagselector.xml
Expand Up @@ -528,7 +528,7 @@
this._tags = yield Zotero.Tags.getAll(this.libraryID, this._types);
for (let tag of this.selection) {
for each(var tag2 in this._tags) {
for (let tag2 of this._tags) {
if (tag == tag2) {
var found = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/fileInterface.js
Expand Up @@ -474,7 +474,7 @@ var Zotero_File_Interface = new function() {
function _doBibliographyOptions(name, items) {
// make sure at least one item is not a standalone note or attachment
var haveRegularItem = false;
for each(var item in items) {
for (let item of items) {
if (item.isRegularItem()) {
haveRegularItem = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/rtfScan.js
Expand Up @@ -460,7 +460,7 @@ var Zotero_RTFScan = new function() {
*/
function _refreshCanAdvance() {
var canAdvance = true;
for each(var itemList in citationItemIDs) {
for (let itemList of citationItemIDs) {
if(itemList.length != 1) {
canAdvance = false;
break;
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/tools/csledit.js
Expand Up @@ -37,7 +37,7 @@ var Zotero_CSL_Editor = new function() {

var styles = Zotero.Styles.getAll();
var currentStyle = null;
for each(var style in styles) {
for (let style of styles) {
if (style.source) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/tools/cslpreview.js
Expand Up @@ -56,7 +56,7 @@ var Zotero_CSL_Preview = new function() {
var styles = Zotero.Styles.getAll();
// XXX needs its own string really for the title!
var str = '<html><head><title></title></head><body>';
for each(var style in styles) {
for (let style of styles) {
if (style.source) {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions chrome/content/zotero/xpcom/annotate.js
Expand Up @@ -141,7 +141,7 @@ Zotero.Annotate = new function() {
} else {
var browsers = win.document.getElementsByTagNameNS(XUL_NAMESPACE, "browser");
}
for each(var browser in browsers) {
for (let browser of browsers) {
if(browser.currentURI) {
if(browser.currentURI.spec == annotationURL) {
if(haveBrowser) {
Expand Down Expand Up @@ -364,7 +364,7 @@ Zotero.Annotate.Path.prototype.fromNode = function(node, offset) {
// is still part of the first text node
if(sibling.getAttribute) {
// get offset of all child nodes
for each(var child in sibling.childNodes) {
for (let child of sibling.childNodes) {
if(child && child.nodeType == TEXT_TYPE) {
this.offset += child.nodeValue.length;
}
Expand Down Expand Up @@ -754,14 +754,14 @@ Zotero.Annotations.prototype.save = function() {
Zotero.Annotations.prototype.load = Zotero.Promise.coroutine(function* () {
// load annotations
var rows = yield Zotero.DB.queryAsync("SELECT * FROM annotations WHERE itemID = ?", [this.itemID]);
for each(var row in rows) {
for (let row of rows) {
var annotation = this.createAnnotation();
annotation.initWithDBRow(row);
}

// load highlights
var rows = yield Zotero.DB.queryAsync("SELECT * FROM highlights WHERE itemID = ?", [this.itemID]);
for each(var row in rows) {
for (let row of rows) {
try {
var highlight = new Zotero.Highlight(this);
highlight.initWithDBRow(row);
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/api.js
Expand Up @@ -76,7 +76,7 @@ Zotero.API = {
var s2 = new Zotero.Search();
s2.setScope(s);
var groups = Zotero.Groups.getAll();
for each(var group in groups) {
for (let group of groups) {
s2.addCondition('libraryID', 'isNot', group.libraryID);
}
var ids = yield s2.search();
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/cite.js
Expand Up @@ -143,7 +143,7 @@ Zotero.Cite = {
output.push(bib[1][i]);

// add COinS
for each(var itemID in bib[0].entry_ids[i]) {
for (let itemID of bib[0].entry_ids[i]) {
try {
var co = Zotero.OpenURL.createContextObject(Zotero.Items.get(itemID), "1.0");
if(!co) continue;
Expand Down
12 changes: 6 additions & 6 deletions chrome/content/zotero/xpcom/collectionTreeView.js
Expand Up @@ -1533,7 +1533,7 @@ Zotero.CollectionTreeView.prototype.canDropCheck = function (row, orient, dataTr
var ids = data;
var items = Zotero.Items.get(ids);
var skip = true;
for each(var item in items) {
for (let item of items) {
// Can only drag top-level items
if (!item.isTopLevelItem()) {
Zotero.debug("Can't drag child item");
Expand Down Expand Up @@ -1738,7 +1738,7 @@ Zotero.CollectionTreeView.prototype.canDropCheckAsync = Zotero.Promise.coroutine
}

var descendents = col.getDescendents(false, 'collection');
for each(var descendent in descendents) {
for (let descendent of descendents) {
descendent = Zotero.Collections.get(descendent.id);
// Disallow if linked collection already exists for any subcollections
//
Expand Down Expand Up @@ -1883,7 +1883,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
if (options.childNotes) {
var noteIDs = item.getNotes();
var notes = Zotero.Items.get(noteIDs);
for each(var note in notes) {
for (let note of notes) {
let newNote = note.clone(targetLibraryID, { skipTags: !options.tags });
newNote.parentID = newItemID;
yield newNote.save({
Expand All @@ -1898,7 +1898,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
if (options.childLinks || options.childFileAttachments) {
var attachmentIDs = item.getAttachments();
var attachments = Zotero.Items.get(attachmentIDs);
for each(var attachment in attachments) {
for (let attachment of attachments) {
var linkMode = attachment.attachmentLinkMode;

// Skip linked files
Expand Down Expand Up @@ -2069,7 +2069,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
var sameLibrary = false;
}

for each(var item in items) {
for (let item of items) {
if (!item.isTopLevelItem()) {
continue;
}
Expand Down Expand Up @@ -2126,7 +2126,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
var lastWin = wm.getMostRecentWindow("navigator:browser");
lastWin.openDialog('chrome://zotero/content/merge.xul', '', 'chrome,modal,centerscreen', io);

for each(var obj in io.dataOut) {
for (let obj of io.dataOut) {
yield obj.ref.save();
}
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/data/cachedTypes.js
Expand Up @@ -283,7 +283,7 @@ Zotero.CreatorTypes = new function() {

var valid = false;
var types = this.getTypesForItemType(itemTypeID);
for each(var type in types) {
for (let type of types) {
if (type.id == creatorTypeID) {
valid = true;
break;
Expand Down
8 changes: 4 additions & 4 deletions chrome/content/zotero/xpcom/data/item.js
Expand Up @@ -447,7 +447,7 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) {
}
}

for each(var oldFieldID in obsoleteFields) {
for (let oldFieldID of obsoleteFields) {
// Try to get a base type for this field
var baseFieldID =
Zotero.ItemFields.getBaseIDFromTypeAndField(oldItemTypeID, oldFieldID);
Expand Down Expand Up @@ -532,14 +532,14 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) {
// Initialize this._itemData with type-specific fields
this._itemData = {};
var fields = Zotero.ItemFields.getItemTypeFields(itemTypeID);
for each(var fieldID in fields) {
for (let fieldID of fields) {
this._itemData[fieldID] = null;
}

// DEBUG: clear change item data?

if (copiedFields) {
for each(var f in copiedFields) {
for (let f of copiedFields) {
// For fields that we moved to different fields in the new type
// (e.g., book -> bookTitle), mark the old value as explicitly
// false in previousData (since otherwise it would be null)
Expand Down Expand Up @@ -3793,7 +3793,7 @@ Zotero.Item.prototype.diff = function (item, includeMatches, ignoreFields) {
throw ("ignoreFields cannot be used if includeMatches is set");
}
var realDiffs = numDiffs;
for each(var field in ignoreFields) {
for (let field of ignoreFields) {
if (diff[0].primary[field] != undefined) {
realDiffs--;
if (realDiffs == 0) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/data/itemFields.js
Expand Up @@ -75,7 +75,7 @@ Zotero.ItemFields = new function() {
var sql = "SELECT DISTINCT baseFieldID FROM baseFieldMappingsCombined";
var baseFields = yield Zotero.DB.columnQueryAsync(sql);

for each(var field in fields) {
for (let field of fields) {
_fields[field['fieldID']] = {
id: field['fieldID'],
name: field.fieldName,
Expand Down Expand Up @@ -440,7 +440,7 @@ Zotero.ItemFields = new function() {
var baseFields = yield Zotero.DB.columnQueryAsync(sql);

var fields = [];
for each(var row in rows) {
for (let row of rows) {
if (!fields[row.itemTypeID]) {
fields[row.itemTypeID] = [];
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/data/items.js
Expand Up @@ -743,12 +743,12 @@ Zotero.Items = function() {
var toSave = {};
toSave[item.id] = item;

for each(var otherItem in otherItems) {
for (let otherItem of otherItems) {
let otherItemURI = Zotero.URI.getItemURI(otherItem);

// Move child items to master
var ids = otherItem.getAttachments(true).concat(otherItem.getNotes(true));
for each(var id in ids) {
for (let id of ids) {
var attachment = yield this.getAsync(id);

// TODO: Skip identical children?
Expand Down
28 changes: 14 additions & 14 deletions chrome/content/zotero/xpcom/data/search.js
Expand Up @@ -255,7 +255,7 @@ Zotero.Search.prototype.clone = function (libraryID) {

var conditions = this.getConditions();

for each(var condition in conditions) {
for (let condition of Object.values(conditions)) {
var name = condition.mode ?
condition.condition + '/' + condition.mode :
condition.condition
Expand Down Expand Up @@ -299,7 +299,7 @@ Zotero.Search.prototype.addCondition = function (condition, operator, value, req
if (condition.match(/^quicksearch/)) {
var parts = Zotero.SearchConditions.parseSearchString(value);

for each(var part in parts) {
for (let part of parts) {
this.addCondition('blockStart');

// If search string is 8 characters, see if this is a item key
Expand Down Expand Up @@ -329,7 +329,7 @@ Zotero.Search.prototype.addCondition = function (condition, operator, value, req
}
else {
var splits = Zotero.Fulltext.semanticSplitter(part.text);
for each(var split in splits) {
for (let split of splits) {
this.addCondition('fulltextWord', operator, split, false);
}
}
Expand Down Expand Up @@ -498,7 +498,7 @@ Zotero.Search.prototype.getConditions = function(){

Zotero.Search.prototype.hasPostSearchFilter = function() {
this._requireData('conditions');
for each(var i in this._conditions){
for (let i of Object.values(this._conditions)) {
if (i.condition == 'fulltextContent'){
return true;
}
Expand Down Expand Up @@ -530,7 +530,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable
var joinMode = 'all';

// Set some variables for conditions to avoid further lookups
for each(var condition in this._conditions) {
for (let condition of Object.values(this._conditions)) {
switch (condition.condition) {
case 'joinMode':
if (condition.operator == 'any') {
Expand Down Expand Up @@ -632,7 +632,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable
// If join mode ANY or there's a quicksearch (which we assume
// fulltextContent is part of), return the union of the main search and
// (a separate fulltext word search filtered by fulltext content)
for each(var condition in this._conditions){
for (let condition of Object.values(this._conditions)){
if (condition['condition']=='fulltextContent'){
var fulltextWordIntersectionFilter = function (val, index, array) !!hash[val];
var fulltextWordIntersectionConditionFilter = function(val, index, array) {
Expand Down Expand Up @@ -669,7 +669,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable
// Add any necessary conditions to the fulltext word search --
// those that are required in an ANY search and any outside the
// quicksearch in an ALL search
for each(var c in this._conditions) {
for (let c of Object.values(this._conditions)) {
if (c.condition == 'blockStart') {
var inQS = true;
continue;
Expand All @@ -688,7 +688,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable
}

var splits = Zotero.Fulltext.semanticSplitter(condition.value);
for each(var split in splits){
for (let split of splits){
s.addCondition('fulltextWord', condition.operator, split);
}
var fulltextWordIDs = yield s.search();
Expand Down Expand Up @@ -1043,7 +1043,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
if (this._hasPrimaryConditions) {
sql += " AND ";

for each(var condition in conditions){
for (let condition of Object.values(conditions)){
var skipOperators = false;
var openParens = 0;
var condSQL = '';
Expand Down Expand Up @@ -1088,7 +1088,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
if (typeFields) {
condSQL += 'fieldID IN (?,';
// Add type-specific fields
for each(var fieldID in typeFields) {
for (let fieldID of typeFields) {
condSQL += '?,';
condSQLParams.push(fieldID);
}
Expand All @@ -1113,7 +1113,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
if (dateFields) {
condSQL += 'fieldID IN (?,';
// Add type-specific date fields (dateEnacted, dateDecided, issueDate)
for each(var fieldID in dateFields) {
for (let fieldID of dateFields) {
condSQL += '?,';
condSQLParams.push(fieldID);
}
Expand Down Expand Up @@ -1148,7 +1148,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
// for the collection/search
if (objLibraryID === undefined) {
let foundLibraryID = false;
for each (let c in this._conditions) {
for (let c of Object.values(this._conditions)) {
if (c.condition == 'libraryID' && c.operator == 'is') {
foundLibraryID = true;
obj = yield objectTypeClass.getByLibraryAndKeyAsync(
Expand Down Expand Up @@ -1246,7 +1246,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
+ 'fileTypeID=?)';
var patterns = yield Zotero.DB.columnQueryAsync(ftSQL, { int: condition.value });
if (patterns) {
for each(str in patterns) {
for (let str of patterns) {
condSQL += 'contentType LIKE ? OR ';
condSQLParams.push(str + '%');
}
Expand Down Expand Up @@ -1402,7 +1402,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
if (useFreeform && dateparts['part']){
go = true;
var parts = dateparts['part'].split(' ');
for each (var part in parts){
for (let part of parts) {
condSQL += " AND SUBSTR(" + condition['field'] + ", 12, 100)";
condSQL += " LIKE ?";
condSQLParams.push('%' + part + '%');
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/duplicates.js
Expand Up @@ -392,7 +392,7 @@ Zotero.Duplicates.prototype._findDuplicates = Zotero.Promise.coroutine(function*

// Match on exact fields
/*var fields = [''];
for each(var field in fields) {
for (let field of fields) {
var sql = "SELECT itemID, value FROM items JOIN itemData USING (itemID) "
+ "JOIN itemDataValues USING (valueID) "
+ "WHERE libraryID=? AND fieldID=? "
Expand Down

0 comments on commit 269e2f8

Please sign in to comment.