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 var to let or const #885

Merged
merged 1 commit into from
Nov 10, 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 @@ -50,6 +50,7 @@
"no-unused-expressions": 0,
"no-useless-call": 2,
"no-useless-concat": 2,
"no-var": 2,
"no-warning-comments": [2, { "terms": ["do not submit"], "location": "anywhere" }],
"object-curly-spacing": [2, "never", {
"objectsInObjects": false,
Expand Down
12 changes: 6 additions & 6 deletions 3p/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ register('twitter', twitter);
* @param {!Object} data
*/
export function draw3p(win, data) {
var type = data.type;
const type = data.type;
assert(window.context.location.originValidated != null,
'Origin should have been validated');
run(type, win, data);
Expand All @@ -65,8 +65,8 @@ export function draw3p(win, data) {
*/
function masterSelection(type) {
// The master has a special name.
var masterName = 'frame_' + type + '_master';
var master;
const masterName = 'frame_' + type + '_master';
let master;
try {
// Try to get the master from the parent. If it does not
// exist yet we get a security exception that we catch
Expand All @@ -87,8 +87,8 @@ function masterSelection(type) {
* Draws an optionally synchronously to the DOM.
*/
window.draw3p = function() {
var fragment = location.hash;
var data = fragment ? JSON.parse(fragment.substr(1)) : {};
const fragment = location.hash;
const data = fragment ? JSON.parse(fragment.substr(1)) : {};
window.context = data._context;
window.context.location = parseUrl(data._context.location.href);
validateParentOrigin(window, window.context.location);
Expand Down Expand Up @@ -120,7 +120,7 @@ function triggerDimensions(width, height) {
}

function nonSensitiveDataPostMessage(type, opt_object) {
var object = opt_object || {};
const object = opt_object || {};
object.type = type;
object.sentinel = 'amp-3p';
window.parent./*OK*/postMessage(object,
Expand Down
12 changes: 6 additions & 6 deletions 3p/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ function getTwttr(global, cb) {
* @param {!Object} data
*/
export function twitter(global, data) {
var tweet = document.createElement('div');
const tweet = document.createElement('div');
tweet.id = 'tweet';
var width = data.initialWindowWidth;
var height = data.initialWindowHeight;
const width = data.initialWindowWidth;
const height = data.initialWindowHeight;
tweet.style.width = '100%';
global.document.getElementById('c').appendChild(tweet);
getTwttr(global, function(twttr) {
// Dimensions are given by the parent frame.
delete data.width;
delete data.height;
twttr.widgets.createTweet(data.tweetid, tweet, data)./*OK*/then(() => {
var iframe = global.document.querySelector('#c iframe');
const iframe = global.document.querySelector('#c iframe');
// Unfortunately the tweet isn't really done at this time.
// We listen for resize to learn when things are
// really done.
Expand All @@ -74,8 +74,8 @@ export function twitter(global, data) {


function render() {
var iframe = global.document.querySelector('#c iframe');
var body = iframe.contentWindow.document.body;
const iframe = global.document.querySelector('#c iframe');
const body = iframe.contentWindow.document.body;
context.updateDimensions(
body./*OK*/offsetWidth,
body./*OK*/offsetHeight + /* margins */ 20);
Expand Down
2 changes: 1 addition & 1 deletion ads/adreactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {writeScript} from '../src/3p';
* @param {!Object} data
*/
export function adreactor(global, data) {
var url = 'https://adserver.adreactor.com' +
const url = 'https://adserver.adreactor.com' +
'/servlet/view/banner/javascript/zone?' +
'zid=' + encodeURIComponent(data.zid) +
'&pid=' + encodeURIComponent(data.pid) +
Expand Down
4 changes: 2 additions & 2 deletions ads/adsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import {writeScript} from '../src/3p';
export function adsense(global, data) {
/*eslint "google-camelcase/google-camelcase": 0*/
global.google_page_url = global.context.canonicalUrl;
var s = document.createElement('script');
const s = document.createElement('script');
s.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
global.document.body.appendChild(s);

var i = document.createElement('ins');
const i = document.createElement('ins');
i.setAttribute('data-ad-client', data['adClient']);
if (data['adSlot']) {
i.setAttribute('data-ad-slot', data['adSlot']);
Expand Down
2 changes: 1 addition & 1 deletion ads/adtech.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {writeScript, validateSrcPrefix, validateSrcContains} from '../src/3p';
* @param {!Object} data
*/
export function adtech(global, data) {
var src = data.src;
const src = data.src;
validateSrcPrefix('https:', src);
validateSrcContains('/addyn/', src);
writeScript(global, src);
Expand Down
6 changes: 3 additions & 3 deletions ads/doubleclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import {loadScript} from '../src/3p';
export function doubleclick(global, data) {
loadScript(global, 'https://www.googletagservices.com/tag/js/gpt.js', () => {
global.googletag.cmd.push(function() {
var dimensions = [[
const dimensions = [[
parseInt(data.width, 10),
parseInt(data.height, 10)
]];
var slot = googletag.defineSlot(data.slot, dimensions, 'c')
const slot = googletag.defineSlot(data.slot, dimensions, 'c')
.addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().set('page_url', context.canonicalUrl);
googletag.enableServices();

if (data.targeting) {
for (var key in data.targeting) {
for (const key in data.targeting) {
slot.setTargeting(key, data.targeting[key]);
}
}
Expand Down
6 changes: 5 additions & 1 deletion build-system/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ module.exports = {
karma: karma,
lintGlobs: [
'**/*.js',
'!{node_modules,build,dist,dist.3p,third_party,build-system}/**/*.*'
'!{node_modules,build,dist,dist.3p,third_party,build-system}/**/*.*',
'!{testing,examples}/**/*.*',
'!gulpfile.js',
'!karma.conf.js',
'!**/local-amp-chrome-extension/background.js',
],
presubmitGlobs: [
'**/*.{css,js}',
Expand Down
2 changes: 1 addition & 1 deletion builtins/amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export function installAd(win) {
a.href = 'https://www.ampproject.org';
a.target = '_blank';
a.setAttribute('fallback', '');
var img = new Image();
const img = new Image();
setStyles(img, {
width: 'auto',
height: '100%',
Expand Down
3 changes: 0 additions & 3 deletions builtins/amp-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {registerElement} from '../src/custom-element';
*/
export function installImg(win) {

/** @type {number} Count of images */
var count = 0;

class AmpImg extends BaseElement {

/** @override */
Expand Down
6 changes: 3 additions & 3 deletions builtins/amp-pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ export function installPixel(win) {

/** @override */
layoutCallback() {
var src = this.element.getAttribute('src');
let src = this.element.getAttribute('src');
src = this.assertSource(src);
src = src.replace(REPLACEMENT_EXPR, function(match, name) {
var val = REPLACEMENTS[name]();
let val = REPLACEMENTS[name]();
if (!val && val !== 0) {
val = '';
}
return encodeURIComponent(val);
});
var image = new Image();
const image = new Image();
image.src = src;
image.width = 1;
image.height = 1;
Expand Down
18 changes: 9 additions & 9 deletions extensions/amp-audio/0.1/test/test-amp-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require('../amp-audio');
adopt(window);

describe('amp-audio', () => {
var iframe;
var ampAudio;
var sandbox;
let iframe;
let ampAudio;
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
Expand All @@ -43,7 +43,7 @@ describe('amp-audio', () => {

function getAmpAudio(attributes, opt_childNodesAttrs) {
ampAudio = iframe.doc.createElement('amp-audio');
for (var key in attributes) {
for (const key in attributes) {
ampAudio.setAttribute(key, attributes[key]);
}
if (opt_childNodesAttrs) {
Expand All @@ -66,7 +66,7 @@ describe('amp-audio', () => {
}

function attachAndRun(attributes, opt_childNodesAttrs) {
var ampAudio = getAmpAudio(attributes, opt_childNodesAttrs);
const ampAudio = getAmpAudio(attributes, opt_childNodesAttrs);
naturalDimensions_['AMP-AUDIO'] = {width: 300, height: 30};
return iframe.addElement(ampAudio);
}
Expand All @@ -75,7 +75,7 @@ describe('amp-audio', () => {
return attachAndRun({
src: 'https://origin.com/audio.mp3'
}).then(a => {
var audio = a.querySelector('audio');
const audio = a.querySelector('audio');
expect(audio).to.be.an.instanceof(Element);
expect(audio.tagName).to.equal('AUDIO');
expect(audio.getAttribute('src'))
Expand All @@ -99,7 +99,7 @@ describe('amp-audio', () => {
{tag: 'source', src: 'https://origin.com/audio.ogg', type: 'audio/ogg'},
{tag: 'text', text: 'Unsupported.'},
]).then(a => {
var audio = a.querySelector('audio');
const audio = a.querySelector('audio');
expect(audio).to.be.an.instanceof(Element);
expect(audio.tagName).to.equal('AUDIO');
expect(a.getAttribute('width')).to.be.equal('503');
Expand All @@ -124,7 +124,7 @@ describe('amp-audio', () => {

it('should set its dimensions to the browser natural', () => {
return attachAndRun({}).then(a => {
var audio = a.querySelector('audio');
const audio = a.querySelector('audio');
expect(a.style.width).to.be.equal('300px');
expect(a.style.height).to.be.equal('30px');
if (/Safari|Firefox/.test(navigator.userAgent)) {
Expand All @@ -141,7 +141,7 @@ describe('amp-audio', () => {
return attachAndRun({
'width': '500'
}).then(a => {
var audio = a.querySelector('audio');
const audio = a.querySelector('audio');
expect(a.style.width).to.be.equal('500px');
expect(a.style.height).to.be.equal('30px');
});
Expand Down
6 changes: 3 additions & 3 deletions extensions/amp-carousel/0.1/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class AmpCarousel extends BaseCarousel {

/** @override */
goCallback(dir, animate) {
var newPos = this.nextPos_(this.pos_, dir);
const newPos = this.nextPos_(this.pos_, dir);
if (newPos != this.pos_) {
var oldPos = this.pos_;
const oldPos = this.pos_;
this.pos_ = newPos;

if (!animate) {
Expand Down Expand Up @@ -160,7 +160,7 @@ export class AmpCarousel extends BaseCarousel {
* @private
*/
preloadNext_(pos, dir) {
var nextPos = this.nextPos_(pos, dir);
const nextPos = this.nextPos_(pos, dir);
if (nextPos != pos) {
this.withinWindow_(nextPos, cell => {
this.schedulePreload(cell);
Expand Down
12 changes: 6 additions & 6 deletions extensions/amp-carousel/0.1/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export class AmpSlides extends BaseCarousel {

/** @override */
goCallback(dir, animate) {
var newIndex = this.nextIndex_(dir);
const newIndex = this.nextIndex_(dir);
if (newIndex != this.currentIndex_) {
var newSlide = this.slides_[newIndex];
var oldSlide = this.slides_[this.currentIndex_];
const newSlide = this.slides_[newIndex];
const oldSlide = this.slides_[this.currentIndex_];
this.currentIndex_ = newIndex;
this.prepareSlide_(newSlide, dir);
if (!animate) {
Expand Down Expand Up @@ -158,7 +158,7 @@ export class AmpSlides extends BaseCarousel {
* @param {number} dir
*/
prepareSlide_(slide, dir) {
var containerWidth = this.element./*OK*/offsetWidth;
const containerWidth = this.element./*OK*/offsetWidth;
st.setStyles(slide, {
transform: st.translateX(dir * containerWidth),
zIndex: 1,
Expand All @@ -175,7 +175,7 @@ export class AmpSlides extends BaseCarousel {
* @return {!Transition}
*/
createTransition_(oldSlide, newSlide, dir) {
var containerWidth = this.element./*OK*/offsetWidth;
const containerWidth = this.element./*OK*/offsetWidth;
return tr.all([
tr.setStyles(newSlide, {
transform: tr.translateX(tr.numeric(dir * containerWidth, 0)),
Expand Down Expand Up @@ -233,7 +233,7 @@ export class AmpSlides extends BaseCarousel {
preloadNext_(dir) {
// TODO(dvoytenko): can we actually preload it here? There's no
// guarantee of it has display!=none.
var nextIndex = this.nextIndex_(dir);
const nextIndex = this.nextIndex_(dir);
if (nextIndex != this.currentIndex_) {
this.schedulePreload(this.slides_[nextIndex]);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-fit-text/0.1/amp-fit-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AmpFitText extends AMP.BaseElement {

/** @override */
buildCallback() {
var childNodes = this.getRealChildNodes();
const childNodes = this.getRealChildNodes();

/** @private @const */
this.content_ = document.createElement('div');
Expand Down
6 changes: 3 additions & 3 deletions extensions/amp-fit-text/0.1/test/test-amp-fit-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('amp-fit-text component', () => {

function getFitText(text, opt_responsive) {
return createIframePromise().then(iframe => {
var ft = iframe.doc.createElement('amp-fit-text');
const ft = iframe.doc.createElement('amp-fit-text');
ft.setAttribute('width', '111');
ft.setAttribute('height', '222');
ft.style.fontFamily = 'Arial';
Expand All @@ -51,9 +51,9 @@ describe('amp-fit-text component', () => {
}

it('renders', () => {
var text = 'Lorem ipsum';
const text = 'Lorem ipsum';
return getFitText(text).then(ft => {
var content = ft.querySelector('.-amp-fit-text-content');
const content = ft.querySelector('.-amp-fit-text-content');
expect(content).to.not.equal(null);
expect(content.textContent).to.equal(text);
});
Expand Down
Loading