From d72e0a7e0731caf5a2efe9cd911ab398d0e3874a Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Thu, 29 Jun 2017 20:49:03 -0700 Subject: [PATCH] Type more extensions. Who knew that we hadn't finished this? :) Part of #9876 --- build-system/tasks/compile.js | 3 + extensions/amp-3q-player/0.1/amp-3q-player.js | 15 ++- extensions/amp-analytics/0.1/amp-analytics.js | 3 +- .../0.1/amp-apester-media.js | 107 ++++++++---------- .../amp-experiment/0.1/amp-experiment.js | 9 +- extensions/amp-experiment/0.1/variant.js | 40 +++---- extensions/amp-fit-text/0.1/amp-fit-text.js | 32 ++++-- extensions/amp-font/0.1/amp-font.js | 27 +++-- extensions/amp-font/0.1/fontloader.js | 4 +- .../0.1/amp-google-vrview-image.js | 23 +++- extensions/amp-iframe/0.1/amp-iframe.js | 99 +++++++++------- extensions/amp-list/0.1/amp-list.js | 13 ++- extensions/amp-mustache/0.1/amp-mustache.js | 1 + gulpfile.js | 20 ++-- src/services.js | 8 +- 15 files changed, 236 insertions(+), 168 deletions(-) diff --git a/build-system/tasks/compile.js b/build-system/tasks/compile.js index e73c7d9709ecd..7787dd2db07de 100644 --- a/build-system/tasks/compile.js +++ b/build-system/tasks/compile.js @@ -154,6 +154,8 @@ function compile(entryModuleFilenames, outputDir, 'extensions/amp-bind/**/*.js', // Needed to access form impl from other extensions 'extensions/amp-form/**/*.js', + // Needed to access UserNotificationManager from other extensions + 'extensions/amp-user-notification/**/*.js', 'src/*.js', 'src/!(inabox)*/**/*.js', '!third_party/babel/custom-babel-helpers.js', @@ -274,6 +276,7 @@ function compile(entryModuleFilenames, outputDir, 'third_party/caja/', 'third_party/closure-library/sha384-generated.js', 'third_party/d3/', + 'third_party/mustache/', 'third_party/vega/', 'third_party/webcomponentsjs/', 'node_modules/', diff --git a/extensions/amp-3q-player/0.1/amp-3q-player.js b/extensions/amp-3q-player/0.1/amp-3q-player.js index a6d6ceb65c31e..cbc1b089128bc 100644 --- a/extensions/amp-3q-player/0.1/amp-3q-player.js +++ b/extensions/amp-3q-player/0.1/amp-3q-player.js @@ -16,13 +16,13 @@ import {isLayoutSizeDefined} from '../../../src/layout'; import {tryParseJson} from '../../../src/json'; -import {user} from '../../../src/log'; +import {user, dev} from '../../../src/log'; import {removeElement} from '../../../src/dom'; import { installVideoManagerForDoc, } from '../../../src/service/video-manager-impl'; import {isObject} from '../../../src/types'; -import {listen} from '../../../src/event-helper'; +import {listen, getData} from '../../../src/event-helper'; import {VideoEvents} from '../../../src/video-interface'; import {videoManagerForDoc} from '../../../src/services'; @@ -89,8 +89,9 @@ class Amp3QPlayer extends AMP.BaseElement { ); this.applyFillContent(iframe, true); - iframe.src = 'https://playout.3qsdn.com/' + - encodeURIComponent(this.dataId) + '?autoplay=false&=true'; + iframe.src = 'https://playout.3qsdn.com/' + + encodeURIComponent(dev().assertString(this.dataId)) + + '?autoplay=false&=true'; this.element.appendChild(iframe); return this.loadPromise(this.iframe_).then(() => @@ -138,12 +139,14 @@ class Amp3QPlayer extends AMP.BaseElement { } } - const data = isObject(event.data) ? event.data : tryParseJson(event.data); + const data = isObject(getData(event)) + ? getData(event) + : tryParseJson(getData(event)); if (data === undefined) { return; } - switch (data.data) { + switch (data['data']) { case 'ready': this.element.dispatchCustomEvent(VideoEvents.LOAD); this.playerReadyResolver_(); diff --git a/extensions/amp-analytics/0.1/amp-analytics.js b/extensions/amp-analytics/0.1/amp-analytics.js index 92a2c195632c1..6180416f243eb 100644 --- a/extensions/amp-analytics/0.1/amp-analytics.js +++ b/extensions/amp-analytics/0.1/amp-analytics.js @@ -145,7 +145,8 @@ export class AmpAnalytics extends AMP.BaseElement { if (this.consentNotificationId_ != null) { this.consentPromise_ = userNotificationManagerFor(this.win) - .then(service => service.get(this.consentNotificationId_)); + .then(service => service.get(dev().assertString( + this.consentNotificationId_))); } if (this.element.getAttribute('trigger') == 'immediate') { diff --git a/extensions/amp-apester-media/0.1/amp-apester-media.js b/extensions/amp-apester-media/0.1/amp-apester-media.js index 751f86d85f46a..d238981e2e6f0 100644 --- a/extensions/amp-apester-media/0.1/amp-apester-media.js +++ b/extensions/amp-apester-media/0.1/amp-apester-media.js @@ -28,7 +28,48 @@ const TAG = 'amp-apester-media'; * AMP Apester-media */ class AmpApesterMedia extends AMP.BaseElement { - /** @override */ + + /** @param {!AmpElement} element */ + constructor(element) { + super(element); + /** + * @const @private {string} + */ + this.rendererBaseUrl_ = 'https://renderer.qmerce.com'; + + /** + * @const @private {string} + */ + this.displayBaseUrl_ = 'https://display.apester.com'; + + /** + * @const @private {string} + */ + this.loaderUrl_ = 'https://images.apester.com/images%2Floader.gif'; + /** @private {boolean} */ + this.seen_ = false; + /** @private {?Element} */ + this.iframe_ = null; + /** @private {?Promise} */ + this.iframePromise_ = null; + /** @private {boolean} */ + this.ready_ = false; + /** @private {?number|undefined} */ + this.width_ = null; + /** @private {?number|undefined} */ + this.height_ = null; + /** @private {boolean} */ + this.random_ = false; + /** + * @private {?string} + */ + this.mediaAttribute_ = null; + } + + /** + * @param {boolean=} onLayout + * @override + */ preconnectCallback(onLayout) { this.preconnect.url(this.displayBaseUrl_, onLayout); this.preconnect.url(this.rendererBaseUrl_, onLayout); @@ -57,40 +98,9 @@ class AmpApesterMedia extends AMP.BaseElement { buildCallback() { const width = this.element.getAttribute('width'); const height = this.element.getAttribute('height'); - - /** - * @private @const {number} - * */ this.width_ = getLengthNumeral(width); - - /** - * @private @const {number} - * */ this.height_ = getLengthNumeral(height); - - /** - * @const @private {string} - */ - this.rendererBaseUrl_ = 'https://renderer.qmerce.com'; - - /** - * @const @private {string} - */ - this.displayBaseUrl_ = 'https://display.apester.com'; - - /** - * @const @private {string} - */ - this.loaderUrl_ = 'https://images.apester.com/images%2Floader.gif'; - - /** - * @private {boolean} - */ this.random_ = false; - - /** - * @const @private {string} - */ this.mediaAttribute_ = user().assert( (this.element.getAttribute('data-apester-media-id') || (this.random_ = @@ -98,26 +108,6 @@ class AmpApesterMedia extends AMP.BaseElement { 'Either the data-apester-media-id or the data-apester-channel-token ' + 'attributes must be specified for %s', this.element); - - /** - * @private {?Element} - */ - this.iframe_ = null; - - /** - * @private {?Promise} - */ - this.iframePromise_ = null; - - /** - * @private {boolean} - */ - this.seen_ = false; - - /** - * @private {boolean} - */ - this.ready_ = false; } /** @override */ @@ -131,7 +121,8 @@ class AmpApesterMedia extends AMP.BaseElement { * @return {string} **/ buildUrl_() { - const encodedMediaAttribute = encodeURIComponent(this.mediaAttribute_); + const encodedMediaAttribute = encodeURIComponent( + dev().assertString(this.mediaAttribute_)); const suffix = (this.random_) ? `/tokens/${encodedMediaAttribute}/interactions/random` : `/interactions/${encodedMediaAttribute}/display`; @@ -241,9 +232,9 @@ class AmpApesterMedia extends AMP.BaseElement { this.element.classList.add('amp-apester-container'); return this.queryMedia_() .then(response => { - const media = response.payload; + const media = response['payload']; const src = this.constructUrlFromMedia_( - media.interactionId); + media['interactionId']); const iframe = this.constructIframe_(src); const overflow = this.constructOverflow_(); const mutate = state => { @@ -262,10 +253,12 @@ class AmpApesterMedia extends AMP.BaseElement { }, error => { dev().error(TAG, 'Display', error); return undefined; - }).then(media => { + }) + /** @param {!JsonObject} media */ + .then(media => { this.togglePlaceholder(false); this.ready_ = true; - const height = 0 || media.data.size.height; + const height = 0 || media['data']['size']['height']; if (height != this.height_) { this.height_ = height; if (this.random_) { diff --git a/extensions/amp-experiment/0.1/amp-experiment.js b/extensions/amp-experiment/0.1/amp-experiment.js index ce915e454cd87..fe30223fec92d 100644 --- a/extensions/amp-experiment/0.1/amp-experiment.js +++ b/extensions/amp-experiment/0.1/amp-experiment.js @@ -14,7 +14,8 @@ * limitations under the License. */ -import {user} from '../../../src/log'; +import {dev, user} from '../../../src/log'; +import {parseJson} from '../../../src/json'; import {Layout} from '../../../src/layout'; import {waitForBodyPromise} from '../../../src/dom'; import {allocateVariant} from './variant'; @@ -53,6 +54,7 @@ export class AmpExperiment extends AMP.BaseElement { }); } + /** @return {!JsonObject} [description] */ getConfig_() { const children = this.element.children; user().assert( @@ -62,7 +64,7 @@ export class AmpExperiment extends AMP.BaseElement { ' should contain exactly one ' + '