diff --git a/.eslintrc.json b/.eslintrc.json index 12b7b508..3f253fb8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "extends": "eslint:recommended", "ecmaVersion": 6, "rules": { - "no-console": 0 + "no-console": 0, + "no-var": "error" }, "env": { "browser": true, diff --git a/gulpfile.js b/gulpfile.js index a6ef501f..b1a79e18 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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()); diff --git a/lib/elements/array-selector.html b/lib/elements/array-selector.html index 62eed7f0..4d9f1df0 100644 --- a/lib/elements/array-selector.html +++ b/lib/elements/array-selector.html @@ -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); * } * }); diff --git a/lib/elements/dom-repeat.html b/lib/elements/dom-repeat.html index 33404f26..a22053a6 100644 --- a/lib/elements/dom-repeat.html +++ b/lib/elements/dom-repeat.html @@ -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 { @@ -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. path change, // responsible for notifying item. 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); * } diff --git a/lib/legacy/legacy-element-mixin.html b/lib/legacy/legacy-element-mixin.html index 136215bb..e3b9c078 100644 --- a/lib/legacy/legacy-element-mixin.html +++ b/lib/legacy/legacy-element-mixin.html @@ -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} 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} 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} List of distributed nodes for the ``. */ 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); diff --git a/lib/legacy/polymer-fn.html b/lib/legacy/polymer-fn.html index da95f308..28f45165 100644 --- a/lib/legacy/polymer-fn.html +++ b/lib/legacy/polymer-fn.html @@ -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 { diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index 9bcb71ec..7224a9fa 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -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)) { diff --git a/lib/mixins/property-accessors.html b/lib/mixins/property-accessors.html index dcb5cd5b..9bef8044 100644 --- a/lib/mixins/property-accessors.html +++ b/lib/mixins/property-accessors.html @@ -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 { diff --git a/lib/mixins/property-effects.html b/lib/mixins/property-effects.html index d27b67e5..894c8afe 100644 --- a/lib/mixins/property-effects.html +++ b/lib/mixins/property-effects.html @@ -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 { diff --git a/lib/utils/path.html b/lib/utils/path.html index b0e839a5..8e6a3e29 100644 --- a/lib/utils/path.html +++ b/lib/utils/path.html @@ -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 1) { // Loop over path parts[0..n-2] and dereference - for (var i=0; i