Skip to content

Commit

Permalink
v-services type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Aug 17, 2016
1 parent cae7c2f commit 4473a3d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ script:
- npm run ava
- gulp lint
- gulp build --fortesting --css-only
# TODO(jridgewell, #4347) Enable once assertions prove truthiness again.
# - gulp check-types
- gulp check-types
- gulp dist --fortesting
- gulp presubmit
# dep-check needs to occur after build since we rely on build to generate
Expand Down
7 changes: 0 additions & 7 deletions ads/ads.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,3 @@ data.antid;
data.anapiid;
window.MADSAdrequest = {};
window.MADSAdrequest.adrequest;
/**
* @constructor
* @param {!Window} global
* @param {!Object} data
*/
window.EzoicAmpAd = function(global, data) {};
window.EzoicAmpAd.prototype.createAd;
2 changes: 1 addition & 1 deletion src/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const COOKIE_EXPIRATION_INTERVAL = COOKIE_MAX_AGE_DAYS * 24 * 60 * 60 * 1000;
/** @const {string} */
const CANARY_EXPERIMENT_ID = 'dev-channel';

/** @type {Object<string, boolean>} */
/** @type {Object<string, boolean>|undefined} */
let toggles_;

/**
Expand Down
1 change: 0 additions & 1 deletion src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ export class Log {
* @param {...*} var_args Arguments substituted into %s in the message.
* @return {T} The value of shouldBeTrueish.
* @template T
* @throws {Error}
*/
/*eslint "google-camelcase/google-camelcase": 0*/
assert(shouldBeTrueish, opt_message, var_args) {
Expand Down
6 changes: 3 additions & 3 deletions src/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export class Observable {

/**
* Fires an event. All observers are called.
* @param {TYPE} event
* @param {TYPE=} opt_event
*/
fire(event) {
fire(opt_event) {
const handlers = this.handlers_;
for (let i = 0; i < handlers.length; i++) {
const handler = handlers[i];
handler(event);
handler(opt_event);
}
}

Expand Down
25 changes: 17 additions & 8 deletions src/service/viewer-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Viewer {
/** @private {number} */
this.prerenderSize_ = 1;

/** @private {string} */
/** @private {ViewportType} */
this.viewportType_ = ViewportType.NATURAL;

/** @private {number} */
Expand Down Expand Up @@ -188,7 +188,7 @@ export class Viewer {
this.isRuntimeOn_ = !parseInt(this.params_['off'], 10);
dev().fine(TAG_, '- runtimeOn:', this.isRuntimeOn_);

this.overtakeHistory_ = parseInt(this.params_['history'], 10) ||
this.overtakeHistory_ = !!(parseInt(this.params_['history'], 10)) ||
this.overtakeHistory_;
dev().fine(TAG_, '- history:', this.overtakeHistory_);

Expand Down Expand Up @@ -237,6 +237,9 @@ export class Viewer {
// Wait for document to become visible.
this.docState_.onVisibilityChanged(this.recheckVisibilityState_.bind(this));

/** @private {function()|undefined} */
this.messagingReadyResolver_ = undefined;

/**
* This promise will resolve when communications channel has been
* established or timeout in 20 seconds. The timeout is needed to avoid
Expand All @@ -248,10 +251,10 @@ export class Viewer {
timerFor(this.win).timeoutPromise(
20000,
new Promise(resolve => {
/** @private @const {function()|undefined} */
this.messagingReadyResolver_ = resolve;
})).catch(reason => {
throw getChannelError(reason);
throw getChannelError(/** @type {!Error|string|undefined} */ (
reason));
}) : null;

/**
Expand All @@ -265,7 +268,8 @@ export class Viewer {
this.messagingReadyPromise_
.catch(reason => {
// Don't fail promise, but still report.
reportError(getChannelError(reason));
reportError(getChannelError(
/** @type {!Error|string|undefined} */ (reason)));
}) : null;

// Trusted viewer and referrer.
Expand All @@ -283,17 +287,22 @@ export class Viewer {
this.isTrustedViewerOrigin_(this.win.location.ancestorOrigins[0]));
trustedViewerPromise = Promise.resolve(trustedViewerResolved);
} else {

/** @private {!function(boolean)|undefined} */
this.trustedViewerResolver_ = undefined;
// Wait for comms channel to confirm the origin.
trustedViewerResolved = undefined;
trustedViewerPromise = new Promise(resolve => {
/** @const @private {!function(boolean)|undefined} */
this.trustedViewerResolver_ = resolve;
});
}

/** @const @private {!Promise<boolean>} */
this.isTrustedViewer_ = trustedViewerPromise;

/** @private {!function(string)|undefined} */
this.viewerOriginResolver_ = undefined;

/** @const @private {!Promise<string>} */
this.viewerOrigin_ = new Promise(resolve => {
if (!this.isEmbedded()) {
Expand Down Expand Up @@ -868,7 +877,7 @@ export class Viewer {
/**
* Requests AMP document to receive a message from Viewer.
* @param {string} eventType
* @param {*} data
* @param {!JSONType} data
* @param {boolean} unusedAwaitResponse
* @return {(!Promise<*>|undefined)}
* @export
Expand Down Expand Up @@ -1065,7 +1074,7 @@ function parseParams_(str, allParams) {

/**
* Creates an error for the case where a channel cannot be established.
* @param {!Error=} opt_reason
* @param {!Error|string=} opt_reason
* @return {!Error}
*/
function getChannelError(opt_reason) {
Expand Down
6 changes: 3 additions & 3 deletions src/service/viewport-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ export class Viewport {
return null;
}
if (this.viewportMeta_ === undefined) {
this.viewportMeta_ = this.win_.document.querySelector(
'meta[name=viewport]');
this.viewportMeta_ = /** @type {?HTMLMetaElement} */ (
this.win_.document.querySelector('meta[name=viewport]'));
if (this.viewportMeta_) {
this.originalViewportMetaString_ = this.viewportMeta_.content;
}
Expand Down Expand Up @@ -1253,7 +1253,7 @@ export function updateViewportMetaString(currentValue, updateParams) {
if (params[k] !== updateParams[k]) {
changed = true;
if (updateParams[k] !== undefined) {
params[k] = updateParams[k];
params[k] = /** @type {string} */ (updateParams[k]);
} else {
delete params[k];
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/vsync-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Vsync {
* will be undefined.
*
* @param {!VsyncTaskSpecDef} task
* @param {VsyncStateDef=} opt_state
* @param {!VsyncStateDef=} opt_state
*/
run(task, opt_state) {
this.tasks_.push(task);
Expand Down
2 changes: 1 addition & 1 deletion src/service/xhr-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Xhr {
if (opt_init && opt_init.responseType == 'document') {
return fetchPolyfill(input, opt_init);
}
return fetchPolyfill(input, opt_init);
return (this.win.fetch || fetchPolyfill).apply(null, arguments);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export let Location;
*/
export function parseUrl(url) {
if (!a) {
a = self.document.createElement('a');
a = /** @type {HTMLAnchorElement} */ (self.document.createElement('a'));
cache = self.UrlCache || (self.UrlCache = Object.create(null));
}

Expand Down Expand Up @@ -200,15 +200,15 @@ export function assertHttpsUrl(
urlString, elementContext, sourceName = 'source') {
user().assert(urlString != null, '%s %s must be available',
elementContext, sourceName);
const url = parseUrl(urlString);
const url = parseUrl(/** @type {string} */ (urlString));
user().assert(
url.protocol == 'https:' || /^(\/\/)/.test(urlString) ||
url.hostname == 'localhost' || endsWith(url.hostname, '.localhost'),
'%s %s must start with ' +
'"https://" or "//" or be relative and served from ' +
'either https or from localhost. Invalid value: %s',
elementContext, sourceName, urlString);
return urlString;
return /** @type {string} */ (urlString);
}

/**
Expand Down

0 comments on commit 4473a3d

Please sign in to comment.