var -> let and turn on lint rule.

This commit is contained in:
Steven Orvell
2017-03-03 15:58:52 -08:00
parent 0cd393fac0
commit 83f0104403
11 changed files with 84 additions and 80 deletions

View File

@@ -2,7 +2,8 @@
"extends": "eslint:recommended",
"ecmaVersion": 6,
"rules": {
"no-console": 0
"no-console": 0,
"no-var": "error"
},
"env": {
"browser": true,

View File

@@ -219,7 +219,7 @@ gulp.task('release', function(cb) {
});
gulp.task('lint', function() {
return gulp.src(['src/**/*.html', 'test/unit/*.html', 'util/*.js'])
return gulp.src(['lib/**/*.html', 'test/unit/*.html', 'util/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());

View File

@@ -377,7 +377,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* ];
* },
* toggleSelection(e) {
* var item = this.$.employeeList.itemForElement(e.target);
* let item = this.$.employeeList.itemForElement(e.target);
* this.$.selector.select(item);
* }
* });

View File

@@ -282,7 +282,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
disconnectedCallback() {
super.disconnectedCallback();
this.__isDetached = true;
for (var i=0; i<this.__instances.length; i++) {
for (let i=0; i<this.__instances.length; i++) {
this.__detachInstance(i);
}
}
@@ -292,8 +292,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// only perform attachment if the element was previously detached.
if (this.__isDetached) {
this.__isDetached = false;
var parent = this.parentNode;
for (var i=0; i<this.__instances.length; i++) {
let parent = this.parentNode;
for (let i=0; i<this.__instances.length; i++) {
this.__attachInstance(i, parent);
}
}
@@ -304,7 +304,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// until ready, since won't have its template content handed back to
// it until then
if (!this.__ctor) {
var template = this.template = this.querySelector('template');
let template = this.template = this.querySelector('template');
if (!template) {
// // Wait until childList changes and template should be there by then
let observer = new MutationObserver(() => {
@@ -319,7 +319,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return false;
}
// Template instance props that should be excluded from forwarding
var instanceProps = {};
let instanceProps = {};
instanceProps[this.as] = true;
instanceProps[this.indexAs] = true;
instanceProps[this.itemsIndexAs] = true;
@@ -328,8 +328,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
parentModel: true,
instanceProps: instanceProps,
forwardHostProp: function(prop, value) {
var i$ = this.__instances;
for (var i=0, inst; (i<i$.length) && (inst=i$[i]); i++) {
let i$ = this.__instances;
for (let i=0, inst; (i<i$.length) && (inst=i$[i]); i++) {
inst.forwardHostProp(prop, value);
}
},
@@ -358,7 +358,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
__sortChanged(sort) {
var methodHost = this.__getMethodHost();
let methodHost = this.__getMethodHost();
this.__sortFn = sort && (typeof sort == 'function' ? sort :
function() { return methodHost[sort].apply(methodHost, arguments); });
this.__needFullRefresh = true;
@@ -368,7 +368,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
__filterChanged(filter) {
var methodHost = this.__getMethodHost();
let methodHost = this.__getMethodHost();
this.__filterFn = filter && (typeof filter == 'function' ? filter :
function() { return methodHost[filter].apply(methodHost, arguments); });
this.__needFullRefresh = true;
@@ -405,8 +405,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// Simple auto chunkSize throttling algorithm based on feedback loop:
// measure actual time between frames and scale chunk count by ratio
// of target/actual frame time
var currChunkTime = performance.now();
var ratio = this._targetFrameTime / (currChunkTime - this.__lastChunkTime);
let currChunkTime = performance.now();
let ratio = this._targetFrameTime / (currChunkTime - this.__lastChunkTime);
this.__chunkCount = Math.round(this.__chunkCount * ratio) || 1;
this.__limit += this.__chunkCount;
this.__lastChunkTime = currChunkTime;
@@ -436,8 +436,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
__handleObservedPaths(path) {
if (this.__observePaths) {
path = path.substring(path.indexOf('.') + 1);
var paths = this.__observePaths;
for (var i=0; i<paths.length; i++) {
let paths = this.__observePaths;
for (let i=0; i<paths.length; i++) {
if (path.indexOf(paths[i]) === 0) {
this.__needFullRefresh = true;
this.__debounceRender(this.__render, this.delay);
@@ -534,21 +534,21 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
__detachInstance(idx) {
var inst = this.__instances[idx];
for (var i=0; i<inst.children.length; i++) {
var el = inst.children[i];
let inst = this.__instances[idx];
for (let i=0; i<inst.children.length; i++) {
let el = inst.children[i];
inst.root.appendChild(el);
}
return inst;
}
__attachInstance(idx, parent) {
var inst = this.__instances[idx];
let inst = this.__instances[idx];
parent.insertBefore(inst.root, this);
}
__detachAndRemoveInstance(idx) {
var inst = this.__detachInstance(idx);
let inst = this.__detachInstance(idx);
if (inst) {
this.__pool.push(inst);
}
@@ -556,7 +556,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
__stampInstance(item, instIdx, itemIdx) {
var model = {};
let model = {};
model[this.as] = item;
model[this.indexAs] = instIdx;
model[this.itemsIndexAs] = itemIdx;
@@ -564,7 +564,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
__insertInstance(item, instIdx, itemIdx) {
var inst = this.__pool.pop();
let inst = this.__pool.pop();
if (inst) {
// TODO(kschaaf): If the pool is shared across turns, hostProps
// need to be re-set to reused instances in addition to item
@@ -575,8 +575,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
} else {
inst = this.__stampInstance(item, instIdx, itemIdx);
}
var beforeRow = this.__instances[instIdx + 1];
var beforeNode = beforeRow ? beforeRow.children[0] : this;
let beforeRow = this.__instances[instIdx + 1];
let beforeNode = beforeRow ? beforeRow.children[0] : this;
this.parentNode.insertBefore(inst.root, beforeNode);
this.__instances[instIdx] = inst;
return inst;
@@ -584,7 +584,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// Implements extension point from Templatize mixin
_showHideChildren(hidden) {
for (var i=0; i<this.__instances.length; i++) {
for (let i=0; i<this.__instances.length; i++) {
this.__instances[i]._showHideChildren(hidden);
}
}
@@ -592,17 +592,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// Called as a side effect of a host items.<key>.<path> path change,
// responsible for notifying item.<path> changes to inst for key
__handleItemPath(path, value) {
var itemsPath = path.slice(6); // 'items.'.length == 6
var dot = itemsPath.indexOf('.');
var itemsIdx = dot < 0 ? itemsPath : itemsPath.substring(0, dot);
let itemsPath = path.slice(6); // 'items.'.length == 6
let dot = itemsPath.indexOf('.');
let itemsIdx = dot < 0 ? itemsPath : itemsPath.substring(0, dot);
// If path was index into array...
if (itemsIdx == parseInt(itemsIdx, 10)) {
var itemSubPath = dot < 0 ? '' : itemsPath.substring(dot+1);
let itemSubPath = dot < 0 ? '' : itemsPath.substring(dot+1);
// See if the item subpath should trigger a full refresh...
if (!this.__handleObservedPaths(itemSubPath)) {
// If not, forward to the instance for that index
var instIdx = this.__itemsIdxToInstIdx[itemsIdx];
var inst = this.__instances[instIdx];
let instIdx = this.__itemsIdxToInstIdx[itemsIdx];
let inst = this.__instances[instIdx];
if (inst) {
let itemPath = this.as + (itemSubPath ? '.' + itemSubPath : '');
// This is effectively `notifyPath`, but avoids some of the overhead
@@ -628,7 +628,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {*} Item associated with the element.
*/
itemForElement(el) {
var instance = this.modelForElement(el);
let instance = this.modelForElement(el);
return instance && instance[this.as];
}
@@ -643,7 +643,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* not correspond to the array index if a user `sort` is applied).
*/
indexForElement(el) {
var instance = this.modelForElement(el);
let instance = this.modelForElement(el);
return instance && instance[this.indexAs];
}
@@ -655,7 +655,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*
* Example:
*
* var model = modelForElement(el);
* let model = modelForElement(el);
* if (model.index < 10) {
* model.set('item.checked', true);
* }

View File

@@ -286,7 +286,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* template content.
*/
instanceTemplate(template) {
var dom = /** @type {DocumentFragment} */
let dom = /** @type {DocumentFragment} */
(document.importNode(template._content || template.content, true));
return dom;
}
@@ -309,13 +309,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
fire(type, detail, options) {
options = options || {};
detail = (detail === null || detail === undefined) ? {} : detail;
var event = new Event(type, {
let event = new Event(type, {
bubbles: options.bubbles === undefined ? true : options.bubbles,
cancelable: Boolean(options.cancelable),
composed: options.composed === undefined ? true: options.composed
});
event.detail = detail;
var node = options.node || this;
let node = options.node || this;
node.dispatchEvent(event)
return event;
}
@@ -331,14 +331,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
listen(node, eventName, methodName) {
node = node || this;
var hbl = this.__boundListeners ||
let hbl = this.__boundListeners ||
(this.__boundListeners = new WeakMap());
var bl = hbl.get(node);
let bl = hbl.get(node);
if (!bl) {
bl = {};
hbl.set(node, bl);
}
var key = eventName + methodName;
let key = eventName + methodName;
if (!bl[key]) {
bl[key] = this._addMethodEventListenerToNode(
node, eventName, methodName, this);
@@ -357,9 +357,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
unlisten(node, eventName, methodName) {
node = node || this;
var bl = this.__boundListeners && this.__boundListeners.get(node);
var key = eventName + methodName;
var handler = bl && bl[key];
let bl = this.__boundListeners && this.__boundListeners.get(node);
let key = eventName + methodName;
let handler = bl && bl[key];
if (handler) {
this._removeEventListenerFromNode(node, eventName, handler);
bl[key] = null;
@@ -405,7 +405,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* `this.getRootNode().host`.
*/
get domHost() {
var root = this.getRootNode();
let root = this.getRootNode();
return (root instanceof DocumentFragment) ? root.host : root;
}
@@ -459,7 +459,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {Array<Node>} List of effctive children.
*/
getEffectiveChildren() {
var list = this.getEffectiveChildNodes();
let list = this.getEffectiveChildNodes();
return list.filter(function(n) {
return (n.nodeType === Node.ELEMENT_NODE);
});
@@ -474,9 +474,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {string} List of effctive children.
*/
getEffectiveTextContent() {
var cn = this.getEffectiveChildNodes();
var tc = [];
for (var i=0, c; (c = cn[i]); i++) {
let cn = this.getEffectiveChildNodes();
let tc = [];
for (let i=0, c; (c = cn[i]); i++) {
if (c.nodeType !== Node.COMMENT_NODE) {
tc.push(c.textContent);
}
@@ -493,7 +493,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {Object<Node>} First effective child node that matches selector.
*/
queryEffectiveChildren(selector) {
var e$ = this.queryDistributedElements(selector);
let e$ = this.queryDistributedElements(selector);
return e$ && e$[0];
}
@@ -521,7 +521,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {Array<Node>} List of distributed nodes for the `<slot>`.
*/
getContentChildNodes(slctr) {
var content = this.root.querySelector(slctr || 'slot');
let content = this.root.querySelector(slctr || 'slot');
return content ? Polymer.dom(content).getDistributedNodes() : [];
}
@@ -621,7 +621,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
isDebouncerActive(jobName) {
this._debouncers = this._debouncers || {};
var debouncer = this._debouncers[jobName];
let debouncer = this._debouncers[jobName];
return !!(debouncer && debouncer.isActive());
}
@@ -633,7 +633,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
flushDebouncer(jobName) {
this._debouncers = this._debouncers || {};
var debouncer = this._debouncers[jobName];
let debouncer = this._debouncers[jobName];
if (debouncer) {
debouncer.flush();
}
@@ -647,7 +647,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
cancelDebouncer(jobName) {
this._debouncers = this._debouncers || {}
var debouncer = this._debouncers[jobName];
let debouncer = this._debouncers[jobName];
if (debouncer) {
debouncer.cancel();
}
@@ -695,12 +695,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {Element} Newly created and configured element.
*/
create(tag, props) {
var elt = document.createElement(tag);
let elt = document.createElement(tag);
if (props) {
if (elt.setProperties) {
elt.setProperties(props);
} else {
for (var n in props) {
for (let n in props) {
elt[n] = props[n];
}
}
@@ -834,14 +834,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {Array} Array containing item removed.
*/
arrayDelete(arrayOrPath, item) {
var index;
let index;
if (Array.isArray(arrayOrPath)) {
index = arrayOrPath.indexOf(item);
if (index >= 0) {
return arrayOrPath.splice(index, 1);
}
} else {
var arr = Polymer.Path.get(this, arrayOrPath);
let arr = Polymer.Path.get(this, arrayOrPath);
index = arr.indexOf(item);
if (index >= 0) {
return this.splice(arrayOrPath, index, 1);

View File

@@ -31,7 +31,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
window.Polymer._polymerFn = function(info) {
// if input is a `class` (aka a function with a prototype), use the prototype
// remember that the `constructor` will never be called
var klass;
let klass;
if (typeof info === 'function') {
klass = info;
} else {

View File

@@ -577,7 +577,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
for (let p in p$) {
let info = p$[p];
if (!this._isPropertyPending(p)) {
var value = typeof info.value == 'function' ?
let value = typeof info.value == 'function' ?
info.value.call(this) :
info.value;
if (this._hasPropertyEffect(p)) {

View File

@@ -18,9 +18,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'use strict';
var caseMap = Polymer.CaseMap;
let caseMap = Polymer.CaseMap;
var microtask = Polymer.Async.microTask;
let microtask = Polymer.Async.microTask;
// Save map of native properties; this forms a blacklist or properties
// that won't have their values "saved" by `saveAccessorValue`, since
@@ -186,7 +186,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_attributeToProperty(attribute, value, type) {
// Don't deserialize back to property if currently reflecting
if (!this.__serializing) {
var property = caseMap.dashToCamelCase(attribute);
let property = caseMap.dashToCamelCase(attribute);
this[property] = this._deserializeValue(value, type);
}
}
@@ -221,7 +221,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @param {string} attribute Attribute name to serialize to.
*/
_valueToNodeAttribute(node, value, attribute) {
var str = this._serializeValue(value);
let str = this._serializeValue(value);
if (str === undefined) {
node.removeAttribute(attribute);
} else {

View File

@@ -410,8 +410,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @private
*/
function runComputedEffect(inst, property, props, oldProps, info) {
var result = runMethodEffect(inst, property, props, oldProps, info);
var computedProp = info.methodInfo;
let result = runMethodEffect(inst, property, props, oldProps, info);
let computedProp = info.methodInfo;
if (inst.__propertyEffects && inst.__propertyEffects[computedProp]) {
inst._setPendingProperty(computedProp, result, true);
} else {

View File

@@ -55,7 +55,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {string} Root property name
*/
root: function(path) {
var dotIndex = path.indexOf('.');
let dotIndex = path.indexOf('.');
if (dotIndex === -1) {
return path;
}
@@ -146,10 +146,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
normalize: function(path) {
if (Array.isArray(path)) {
var parts = [];
for (var i=0; i<path.length; i++) {
var args = path[i].toString().split('.');
for (var j=0; j<args.length; j++) {
let parts = [];
for (let i=0; i<path.length; i++) {
let args = path[i].toString().split('.');
for (let j=0; j<args.length; j++) {
parts.push(args[j]);
}
}
@@ -194,14 +194,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* fully dereferenced.
*/
get: function(root, path, info) {
var prop = root;
var parts = this.split(path);
let prop = root;
let parts = this.split(path);
// Loop over path parts[0..n-1] and dereference
for (var i=0; i<parts.length; i++) {
for (let i=0; i<parts.length; i++) {
if (!prop) {
return;
}
var part = parts[i];
let part = parts[i];
prop = prop[part];
}
if (info) {
@@ -221,13 +221,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @return {string | undefined} The normalized version of the input path
*/
set: function(root, path, value) {
var prop = root;
var parts = this.split(path);
var last = parts[parts.length-1];
let prop = root;
let parts = this.split(path);
let last = parts[parts.length-1];
if (parts.length > 1) {
// Loop over path parts[0..n-2] and dereference
for (var i=0; i<parts.length-1; i++) {
var part = parts[i];
for (let i=0; i<parts.length-1; i++) {
let part = parts[i];
prop = prop[part];
if (!prop) {
return;

View File

@@ -2,6 +2,9 @@
"env": {
"mocha": true
},
"rules": {
"no-var": "off"
},
"globals": {
"assert": true,
"sinon": true,