Skip to content

Commit

Permalink
get closure-type-checking running again
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed May 27, 2016
1 parent b13fd64 commit b156816
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 18 deletions.
16 changes: 10 additions & 6 deletions closure/closure-type-checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,26 @@ const closureCompiler = require('google-closure-compiler').gulp();
const gulp = require('gulp');
const gutil = require('gulp-util');
const replace = require('gulp-replace');
const devtoolsRequire =
'const DevtoolsTimelineModel = require(\'../lib/traces/devtools-timeline-model\');';

/* eslint-disable camelcase */
gulp.task('js-compile', function() {
return gulp.src([
'closure/typedefs/*.js',
'closure/third_party/*.js',
'audits/**/*.js',
'lib/icons.js',
'aggregators/**/*.js'
'src/audits/**/*.js',
'src/lib/icons.js',
'src/aggregators/**/*.js'
])
// TODO: hack to remove `require`s that Closure currently can't resolve.
.pipe(replace(devtoolsRequire, ''))
.pipe(replace('require(\'../../lib/web-inspector\').Color.parse;',
'WebInspector.Color.parse;'))
.pipe(replace('require(\'../../lib/traces/tracing-processor\');', '/** @type {?} */ (null);'))
.pipe(replace('require(\'speedline\');', 'function(arg) {};'))
.pipe(replace('require(\'../../../formatters/formatter\');', '{};'))

// Replace any non-local import (e.g. not starting with .) with a dummy type. These are likely
// the built-in Node modules. But not always, so TODO(samthor): Fix this.
.pipe(replace(/require\(\'[^\.].*?\'\)/g, '/** @type {*} */ ({})'))

.pipe(closureCompiler({
compilation_level: 'SIMPLE',
Expand Down
27 changes: 27 additions & 0 deletions closure/third_party/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @externs
*/

/** @type {string} */
var __dirname = '';

/** @type {!Object} */
var global = {};

9 changes: 9 additions & 0 deletions closure/typedefs/Aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ AggregationCriterion.prototype.value;
/** @type {number} */
AggregationCriterion.prototype.weight;

/** @type {boolean|undefined} */
AggregationCriterion.prototype.comingSoon;

/** @type {string|undefined} */
AggregationCriterion.prototype.category;

/** @type {string|undefined} */
AggregationCriterion.prototype.description;

/**
* @typedef {!Object<!AggregationCriterion>}
*/
Expand Down
6 changes: 6 additions & 0 deletions closure/typedefs/Artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,11 @@ Artifacts.prototype.viewport;
/** @type {number} */
Artifacts.prototype.responseCode;

/** @type {number} */
Artifacts.prototype.offlineResponseCode;

/** @type {{value: boolean, debugString: (string|undefined)}} */
Artifacts.prototype.redirectsHTTP;

/** @type {!Accessibility} */
Artifacts.prototype.accessibility;
14 changes: 9 additions & 5 deletions closure/typedefs/AuditResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ AuditResultInput.prototype.debugString;
/** @type {(boolean|number|string|undefined|null)} */
AuditResultInput.prototype.optimalValue;

/** @type {(AuditExtendedInfo|undefined|null)} */
AuditResultInput.prototype.extendedInfo;


/**
* @struct
* @record
*/
function AuditExtendedInfo() {}

/** @type {!string} */
/** @type {string} */
AuditExtendedInfo.prototype.formatter;

/** @type {!Object} */
/** @type {Object|undefined} */
AuditExtendedInfo.prototype.value;

/**
Expand All @@ -71,11 +75,11 @@ AuditResult.prototype.optimalValue;
/** @type {(AuditExtendedInfo|undefined|null)} */
AuditResult.prototype.extendedInfo;

/** @type {string} */
/** @type {(string|undefined)} */
AuditResult.prototype.name;

/** @type {string} */
/** @type {(string|undefined)} */
AuditResult.prototype.category;

/** @type {string} */
/** @type {(string|undefined)} */
AuditResult.prototype.description;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"devDependencies": {
"eslint": "^2.4.0",
"eslint-config-google": "^0.4.0",
"google-closure-compiler": "^20160315.0.0",
"google-closure-compiler": "^20160517.0.0",
"gulp": "^3.9.1",
"gulp-replace": "^0.5.4",
"gulp-util": "^3.0.7",
Expand Down
4 changes: 2 additions & 2 deletions src/aggregators/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Aggregate {
*/
static _filterResultsByAuditNames(results, expected) {
const expectedNames = Object.keys(expected);
return results.filter(r => expectedNames.indexOf(r.name) !== -1);
return results.filter(r => expectedNames.indexOf(/** @type {string} */ (r.name)) !== -1);
}

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ class Aggregate {
// TODO(paullewis): Remove once coming soon audits have landed.
if (expected[e].comingSoon) {
subItems.push({
value: String.raw`¯\_(ツ)_/¯`,
value: '¯\\_(ツ)_/¯', // TODO(samthor): Patch going to Closure, String.raw is badly typed
name: 'coming-soon',
category: expected[e].category,
description: expected[e].description,
Expand Down
2 changes: 1 addition & 1 deletion src/aggregators/is-performant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const firstMeaningfulPaint = require('../../audits/performance/first-meaningful-
const speedIndexMetric = require('../../audits/performance/speed-index-metric').name;

// TODO: https://github.com/GoogleChrome/lighthouse/issues/336
/** @type {string} */
// /** @type {string} */
// const inputReadinessMetric = require('../../audits/performance/input-readiness-metric').name;

class IsPerformant extends Aggregate {
Expand Down
5 changes: 3 additions & 2 deletions src/audits/performance/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FirstMeaningfulPaint extends Audit {
* @see https://github.com/GoogleChrome/lighthouse/issues/26
* @see https://docs.google.com/document/d/1BR94tJdZLsin5poeet0XoTW60M0SjvOJQttKT-JK8HI/view
* @param {!Artifacts} artifacts The artifacts from the gather phase.
* @return {!AuditResult} The score from the audit, ranging from 0-100.
* @return {!Promise<!AuditResult>} The score from the audit, ranging from 0-100.
*/
static audit(artifacts) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -241,8 +241,9 @@ module.exports = FirstMeaningfulPaint;

/**
* Math.max, but with NaN values removed
* @param {...number} _
*/
function max() {
function max(_) {
const args = [...arguments].filter(val => !isNaN(val));
return Math.max.apply(Math, args);
}
2 changes: 1 addition & 1 deletion src/audits/performance/speed-index-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SpeedIndexMetric extends Audit {
* Audits the page to give a score for the Speed Index.
* @see https://github.com/GoogleChrome/lighthouse/issues/197
* @param {!Artifacts} artifacts The artifacts from the gather phase.
* @return {!AuditResult} The score from the audit, ranging from 0-100.
* @return {!Promise<!AuditResult>} The score from the audit, ranging from 0-100.
*/
static audit(artifacts) {
return Promise.resolve(artifacts.traceContents).then(trace => {
Expand Down

0 comments on commit b156816

Please sign in to comment.