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

switch let to const when possible #817

Merged
merged 1 commit into from
Oct 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"no-useless-call": 2,
"no-useless-concat": 2,
"no-warning-comments": [2, { "terms": ["do not submit"], "location": "anywhere" }],
"prefer-const": 2,
"radix": 2,
"semi": 2,
"space-after-keywords": 2,
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function lint() {
}

return stream.pipe(eslint(options))
.pipe(eslint.formatEach('compact', function(msg) {
.pipe(eslint.formatEach('stylish', function(msg) {
errorsFound = true;
util.log(util.colors.red(msg));
}))
Expand Down
32 changes: 16 additions & 16 deletions builtins/amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ const POSITION_FIXED_TAG_WHITELIST = {
*/
export function scoreDimensions_(dims, maxWidth, maxHeight) {
return dims.map(function(dim) {
let width = dim[0];
let height = dim[1];
let widthScore = Math.abs(width - maxWidth);
const width = dim[0];
const height = dim[1];
const widthScore = Math.abs(width - maxWidth);
// if the width is over the max then we need to penalize it
let widthPenalty = Math.abs((maxWidth - width) * 3);
const widthPenalty = Math.abs((maxWidth - width) * 3);
// we add a multiplier to height as we prioritize it more than width
let heightScore = Math.abs(height - maxHeight) * 2;
const heightScore = Math.abs(height - maxHeight) * 2;
// if the height is over the max then we need to penalize it
let heightPenalty = Math.abs((maxHeight - height) * 2.5);
const heightPenalty = Math.abs((maxHeight - height) * 2.5);

return (widthScore - widthPenalty) + (heightScore - heightPenalty);
});
Expand All @@ -84,7 +84,7 @@ export function scoreDimensions_(dims, maxWidth, maxHeight) {
*/
export function upgradeImages_(images) {
Object.keys(images).forEach(key => {
let curDimImgs = images[key];
const curDimImgs = images[key];
curDimImgs.forEach((item, index) => {
curDimImgs[index] = item.replace(/@1x\.png$/, '@2x.png');
});
Expand Down Expand Up @@ -148,9 +148,9 @@ export function installAd(win) {
prefetchAd_() {
// We always need the bootstrap.
prefetchBootstrap(this.getWin());
let type = this.element.getAttribute('type');
let prefetch = adPrefetch[type];
let preconnect = adPreconnect[type];
const type = this.element.getAttribute('type');
const prefetch = adPrefetch[type];
const preconnect = adPreconnect[type];
if (typeof prefetch == 'string') {
this.preconnect.prefetch(prefetch);
} else if (prefetch) {
Expand All @@ -166,7 +166,7 @@ export function installAd(win) {
});
}
// If fully qualified src for ad script is specified we prefetch that.
let src = this.element.getAttribute('src');
const src = this.element.getAttribute('src');
if (src) {
this.preconnect.prefetch(src);
}
Expand All @@ -187,7 +187,7 @@ export function installAd(win) {
*/
isPositionFixed() {
let el = this.element;
let body = el.ownerDocument.body;
const body = el.ownerDocument.body;
do {
if (POSITION_FIXED_TAG_WHITELIST[el.tagName]) {
return false;
Expand Down Expand Up @@ -248,7 +248,7 @@ export function installAd(win) {
margin: 'auto',
});

let winner = this.getPlaceholderImage_();
const winner = this.getPlaceholderImage_();
img.src = `https://ampproject.org/backfill/${winner}`;
this.placeholder_ = a;
a.appendChild(img);
Expand All @@ -261,12 +261,12 @@ export function installAd(win) {
* @return {string} The image URL.
*/
getPlaceholderImage_() {
let scores = scoreDimensions_(BACKFILL_DIMENSIONS_,
const scores = scoreDimensions_(BACKFILL_DIMENSIONS_,
this.element./*REVIEW*/clientWidth,
this.element./*REVIEW*/clientHeight);
let dims = BACKFILL_DIMENSIONS_[
const dims = BACKFILL_DIMENSIONS_[
scores.indexOf(Math.max.apply(Math, scores))];
let images = BACKFILL_IMGS_[dims.join('x')];
const images = BACKFILL_IMGS_[dims.join('x')];
// do we need a more sophisticated randomizer?
return images[Math.floor(Math.random() * images.length)];
}
Expand Down
2 changes: 1 addition & 1 deletion builtins/amp-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function installImg(win) {
if (this.getLayoutWidth() <= 0) {
return Promise.resolve();
}
let src = this.srcset_.select(this.getLayoutWidth(), this.getDpr()).url;
const src = this.srcset_.select(this.getLayoutWidth(), this.getDpr()).url;
if (src == this.img_.getAttribute('src')) {
return Promise.resolve();
}
Expand Down
8 changes: 4 additions & 4 deletions builtins/amp-pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export function installPixel(win) {
* Returns the host of the canonical URL for this AMP document.
*/
'CANONICAL_HOST': () => {
let url = parseUrl(documentInfoFor(win).canonicalUrl);
const url = parseUrl(documentInfoFor(win).canonicalUrl);
return url && url.hostname;
},

/**
* Returns the path of the canonical URL for this AMP document.
*/
'CANONICAL_PATH': () => {
let url = parseUrl(documentInfoFor(win).canonicalUrl);
const url = parseUrl(documentInfoFor(win).canonicalUrl);
return url && url.pathname;
},

Expand Down Expand Up @@ -88,7 +88,7 @@ export function installPixel(win) {
* Returns the host of the URL for this AMP document.
*/
'AMPDOC_HOST': () => {
let url = parseUrl(win.location.href);
const url = parseUrl(win.location.href);
return url && url.hostname;
}
};
Expand All @@ -98,7 +98,7 @@ export function installPixel(win) {
*/
const REPLACEMENT_EXPR = (() => {
let all = '';
for (let k in REPLACEMENTS) {
for (const k in REPLACEMENTS) {
all += (all.length > 0 ? '|' : '') + k;
}
return new RegExp('\\$(' + all + ')', 'g');
Expand Down
6 changes: 3 additions & 3 deletions builtins/amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export function installVideo(win) {

/** @override */
layoutCallback() {
let width = this.element.getAttribute('width');
let height = this.element.getAttribute('height');
let video = document.createElement('video');
const width = this.element.getAttribute('width');
const height = this.element.getAttribute('height');
const video = document.createElement('video');
if (!video.play) {
this.toggleFallback(true);
return Promise.resolve();
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-anim/0.1/amp-anim.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AmpAnim extends AMP.BaseElement {

/** @private */
updateInViewport_() {
let inViewport = this.isInViewport();
const inViewport = this.isInViewport();
this.togglePlaceholder(!inViewport);
st.toggle(this.img_, inViewport);
}
Expand All @@ -99,7 +99,7 @@ class AmpAnim extends AMP.BaseElement {
if (this.getLayoutWidth() <= 0) {
return Promise.resolve();
}
let src = this.srcset_.select(this.getLayoutWidth(),
const src = this.srcset_.select(this.getLayoutWidth(),
this.getDpr()).url;
if (src == this.img_.getAttribute('src')) {
return Promise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-audio/0.1/amp-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class AmpAudio extends AMP.BaseElement {

/** @override */
layoutCallback() {
let audio = document.createElement('audio');
const audio = document.createElement('audio');
if (!audio.play) {
this.toggleFallback(true);
return Promise.resolve();
Expand Down
10 changes: 5 additions & 5 deletions extensions/amp-audio/0.1/test/test-amp-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('amp-audio', () => {
child = iframe.doc.createTextNode(childNodeAttrs.text);
} else {
child = iframe.doc.createElement(childNodeAttrs.tag);
for (let key in childNodeAttrs) {
for (const key in childNodeAttrs) {
if (key !== 'tag') {
child.setAttribute(key, childNodeAttrs[key]);
}
Expand Down Expand Up @@ -148,17 +148,17 @@ describe('amp-audio', () => {
});

it('should fallback when not available', () => {
let savedCreateElement = document.createElement;
const savedCreateElement = document.createElement;
document.createElement = name => {
if (name == 'audio') {
return savedCreateElement.call(document, 'audio2');
}
return savedCreateElement.call(document, name);
};
let element = document.createElement('div');
const element = document.createElement('div');
element.toggleFallback = sinon.spy();
let audio = new AmpAudio(element);
let promise = audio.layoutCallback();
const audio = new AmpAudio(element);
const promise = audio.layoutCallback();
document.createElement = savedCreateElement;
return promise.then(() => {
expect(audio.audio_).to.be.undefined;
Expand Down
32 changes: 16 additions & 16 deletions extensions/amp-carousel/0.1/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export class AmpCarousel extends BaseCarousel {
* @private
*/
nextPos_(pos, dir) {
let containerWidth = this.element./*OK*/offsetWidth;
let fullWidth = this.container_./*OK*/scrollWidth;
let newPos = pos + dir * containerWidth;
const containerWidth = this.element./*OK*/offsetWidth;
const fullWidth = this.container_./*OK*/scrollWidth;
const newPos = pos + dir * containerWidth;
if (newPos < 0) {
return 0;
}
Expand All @@ -134,9 +134,9 @@ export class AmpCarousel extends BaseCarousel {
* @private
*/
withinWindow_(pos, callback) {
let containerWidth = this.getLayoutWidth();
const containerWidth = this.getLayoutWidth();
for (let i = 0; i < this.cells_.length; i++) {
let cell = this.cells_[i];
const cell = this.cells_[i];
if (cell./*OK*/offsetLeft + cell./*OK*/offsetWidth >= pos &&
cell./*OK*/offsetLeft <= pos + containerWidth) {
callback(cell);
Expand Down Expand Up @@ -174,7 +174,7 @@ export class AmpCarousel extends BaseCarousel {
* @private
*/
updateInViewport_(newPos, oldPos) {
let seen = [];
const seen = [];
this.withinWindow_(newPos, cell => {
seen.push(cell);
this.updateInViewport(cell, true);
Expand All @@ -201,7 +201,7 @@ export class AmpCarousel extends BaseCarousel {
/** @private {?Motion} */
this.motion_ = null;

let gestures = Gestures.get(this.element);
const gestures = Gestures.get(this.element);
gestures.onGesture(SwipeXRecognizer, e => {
if (e.data.first) {
this.onSwipeStart_(e.data);
Expand Down Expand Up @@ -253,7 +253,7 @@ export class AmpCarousel extends BaseCarousel {
if (Math.abs(swipe.velocityX) > 0.1) {
this.motion_ = continueMotion(this.pos_, 0, -swipe.velocityX, 0,
(x, y) => {
let newPos = (this.boundPos_(x, true) +
const newPos = (this.boundPos_(x, true) +
this.boundPos_(x, false)) * 0.5;
if (Math.abs(newPos - this.pos_) <= 1) {
// Hit the wall: stop motion.
Expand All @@ -270,11 +270,11 @@ export class AmpCarousel extends BaseCarousel {
promise = Promise.resolve();
}
return promise.then(() => {
let newPos = this.boundPos_(this.pos_, false);
const newPos = this.boundPos_(this.pos_, false);
if (Math.abs(newPos - this.pos_) < 1) {
return undefined;
}
let posFunc = tr.numeric(this.pos_, newPos);
const posFunc = tr.numeric(this.pos_, newPos);
return Animation.animate(time => {
this.pos_ = posFunc(time);
st.setStyles(this.container_, {
Expand All @@ -290,8 +290,8 @@ export class AmpCarousel extends BaseCarousel {

/** @private */
updateBounds_() {
let containerWidth = this.element./*OK*/offsetWidth;
let scrollWidth = this.container_./*OK*/scrollWidth;
const containerWidth = this.element./*OK*/offsetWidth;
const scrollWidth = this.container_./*OK*/scrollWidth;
this.minPos_ = 0;
this.maxPos_ = Math.max(scrollWidth - containerWidth, 0);
this.extent_ = Math.min(containerWidth * 0.4, 200);
Expand All @@ -304,7 +304,7 @@ export class AmpCarousel extends BaseCarousel {
* @private
*/
boundPos_(pos, allowExtent) {
let extent = allowExtent ? this.extent_ : 0;
const extent = allowExtent ? this.extent_ : 0;
return Math.min(this.maxPos_ + extent,
Math.max(this.minPos_ - extent, pos));
}
Expand All @@ -316,9 +316,9 @@ export class AmpCarousel extends BaseCarousel {

/** @override */
hasNext() {
let containerWidth = this.getLayoutWidth();
let scrollWidth = this.container_./*OK*/scrollWidth;
let maxPos = Math.max(scrollWidth - containerWidth, 0);
const containerWidth = this.getLayoutWidth();
const scrollWidth = this.container_./*OK*/scrollWidth;
const maxPos = Math.max(scrollWidth - containerWidth, 0);
return this.pos_ != maxPos;
}
}
Loading