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

get closure-type-checking running again #360

Merged
merged 2 commits into from
May 27, 2016
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
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\');', '{};'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes me sad, but I assume we can remove it as we add annotations to the formatters, etc?


// 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
9 changes: 9 additions & 0 deletions closure/typedefs/Artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,14 @@ 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;

/** @type {!Object<!Object>} */
Artifacts.prototype.criticalRequestChains;
17 changes: 12 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,14 @@ 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;

/** @type {(boolean|undefined)} */
AuditResult.prototype.contributesToScore;
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noooooooooo!

Fine.

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
4 changes: 2 additions & 2 deletions src/audits/performance/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CriticalRequestChains extends Audit {
*/
static audit(artifacts) {
let chainCount = 0;
function walk(node, depth, startTime) {
function walk(node, depth) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated to the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind you, it's fine actually... the fix needs to exist. Go for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Closure fails without this fix. That's one of the points of this
change :)

On Fri., 27 May 2016, 18:53 Paul Lewis, notifications@github.com wrote:

In src/audits/performance/critical-request-chains.js
#360 (comment)
:

@@ -63,7 +63,7 @@ class CriticalRequestChains extends Audit {
*/
static audit(artifacts) {
let chainCount = 0;

  • function walk(node, depth, startTime) {
  • function walk(node, depth) {

Mind you, it's fine actually... the fix needs to exist. Go for it.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/GoogleChrome/lighthouse/pull/360/files/3bf74374fb5c3c808e3e29f6713ee6153dce370f#r64875642,
or mute the thread
https://github.com/notifications/unsubscribe/AAHRkKZ1azw0_yLRageNFSfcdLDo4A9Bks5qFrDtgaJpZM4InRU2
.

const children = Object.keys(node);

// Since a leaf node indicates the end of a chain, we can inspect the number
Expand All @@ -74,7 +74,7 @@ class CriticalRequestChains extends Audit {

children.forEach(id => {
const child = node[id];
walk(child.children, depth + 1, startTime);
walk(child.children, depth + 1);
}, '');
}

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