Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani committed Apr 27, 2017
1 parent 39b5aca commit 42909d1
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 79 deletions.
6 changes: 4 additions & 2 deletions src/core/analysis-cache.ts
Expand Up @@ -113,9 +113,11 @@ export class AnalysisCache {
toString() {
return `<AnalysisCache
scannedDocuments:
${Array.from(this.scannedDocuments.keys()).join('\n ')}
${Array.from(this.scannedDocuments.keys())
.join('\n ')}
analyzedDocuments:
${Array.from(this.analyzedDocuments.keys()).join('\n ')}
${Array.from(this.analyzedDocuments.keys())
.join('\n ')}
>`;
}
}
2 changes: 1 addition & 1 deletion src/core/async-work-cache.ts
Expand Up @@ -50,7 +50,7 @@ export class AsyncWorkCache<K, V> {
return promise;
}

delete(key: K) {
delete (key: K) {
this._keyToResultMap.delete(key);
}

Expand Down
4 changes: 2 additions & 2 deletions src/generate-analysis.ts
Expand Up @@ -150,8 +150,8 @@ export class ValidationError extends Error {
const message = `Unable to validate serialized Polymer analysis. ` +
`Got ${result.errors.length} errors: ` +
`${
result.errors.map((err) => ' ' + (err.message || err)).join('\n')
}`;
result.errors.map((err) => ' ' + (err.message || err)).join('\n')
}`;
super(message);
this.errors = result.errors;
}
Expand Down
6 changes: 4 additions & 2 deletions src/javascript/class-scanner.ts
Expand Up @@ -133,7 +133,8 @@ export class ClassScanner implements JavaScriptScanner {
}
// Classes explicitly defined as elements in their jsdoc tags.
// TODO(justinfagnani): remove @polymerElement support
if (jsdoc.hasTag(class_.jsdoc, 'customElement') || jsdoc.hasTag(class_.jsdoc, 'polymerElement')) {
if (jsdoc.hasTag(class_.jsdoc, 'customElement') ||
jsdoc.hasTag(class_.jsdoc, 'polymerElement')) {
customElements.push({class_});
continue;
}
Expand Down Expand Up @@ -365,7 +366,8 @@ class ClassFinder implements Visitor {
this._classFound(name, doc, value);
} else {
// TODO(justinfagnani): remove @polymerElement support
if (jsdoc.hasTag(doc, 'customElement') || jsdoc.hasTag(doc, 'polymerElement')) {
if (jsdoc.hasTag(doc, 'customElement') ||
jsdoc.hasTag(doc, 'polymerElement')) {
this._classFound(assignedName, doc, value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/esutil.ts
Expand Up @@ -100,7 +100,7 @@ export function closureType(
code: 'no-closure-type',
message:
`Unable to determine closure type for expression of type ${
node.type
node.type
}`,
severity: Severity.WARNING, sourceRange
});
Expand Down
3 changes: 2 additions & 1 deletion src/javascript/function-scanner.ts
Expand Up @@ -118,7 +118,8 @@ class FunctionVisitor implements Visitor {

const docs = jsdoc.parseJsdoc(comment);
// TODO(justinfagnani): remove polymerMixin support
if (jsdoc.hasTag(docs, 'mixinFunction') || jsdoc.hasTag(docs, 'polymerMixin')) {
if (jsdoc.hasTag(docs, 'mixinFunction') ||
jsdoc.hasTag(docs, 'polymerMixin')) {
// This is a mixin, not a normal function.
return;
}
Expand Down
20 changes: 12 additions & 8 deletions src/javascript/jsdoc.ts
Expand Up @@ -62,7 +62,9 @@ function parseCustomTags(tags: Tag[]): Tag[] {
const name = match[1];
const description = match[2];
return {
...tag, name, description,
...tag,
name,
description,
};
}
}
Expand Down Expand Up @@ -142,7 +144,8 @@ export function getMixinApplications(
docs: Annotation,
warnings: Warning[]): ScannedReference[] {
// TODO(justinfagnani): remove @mixes support
const appliesMixinAnnotations = docs.tags!.filter((tag) => tag.title === 'appliesMixin' || tag.title === 'mixes');
const appliesMixinAnnotations = docs.tags!.filter(
(tag) => tag.title === 'appliesMixin' || tag.title === 'mixes');
return appliesMixinAnnotations
.map((annotation) => {
const mixinId = annotation.name;
Expand All @@ -168,11 +171,12 @@ export function extractDemos(jsdoc: Annotation|undefined, baseUrl: string):
return [];
}
const demos: Array<{desc: string | undefined, path: string}> = [];
jsdoc.tags.filter((tag) => tag.title === 'demo' && tag.name).forEach((tag) => {
demos.push({
desc: tag.description || undefined,
path: url.resolve(baseUrl, tag.name!)
});
});
jsdoc.tags.filter((tag) => tag.title === 'demo' && tag.name)
.forEach((tag) => {
demos.push({
desc: tag.description || undefined,
path: url.resolve(baseUrl, tag.name!)
});
});
return demos;
}
13 changes: 6 additions & 7 deletions src/model/document.ts
Expand Up @@ -379,13 +379,12 @@ export class Document implements Feature, Queryable {
let subResult = localFeature.toString();
if (subResult === '[object Object]') {
subResult = `<${
localFeature.constructor.name
} kinds="${
Array.from(localFeature.kinds).join(', ')
}" ids="${
Array.from(localFeature.identifiers)
.join(',')
}">}`;
localFeature.constructor.name
} kinds="${
Array.from(localFeature.kinds).join(', ')
}" ids="${
Array.from(localFeature.identifiers).join(',')
}">}`;
}
result.push(` ${subResult}`);
}
Expand Down
62 changes: 40 additions & 22 deletions src/perf/parse-all-benchmark.ts
Expand Up @@ -108,28 +108,47 @@ async function measure() {
const afterMoreAnalyses = process.memoryUsage().rss;
console.log(
`Additional memory used in analyzing all Polymer-owned code: ${
MiB(afterInitialAnalyses -
initialMemUse)
MiB(afterInitialAnalyses - initialMemUse)
}`);
const leakedMemory = afterMoreAnalyses - afterInitialAnalyses;
const leakedMemory =
afterMoreAnalyses -
afterInitialAnalyses;
console.log(
`Additional memory used after 100 more incremental analyses: ${
MiB(afterMoreAnalyses -
afterInitialAnalyses)
MiB(afterMoreAnalyses - afterInitialAnalyses)
}`);

// TODO(rictic): looks like we've got a memory leak. Need to track this down.
// This should be < 10MiB, not < 100 MiB.
const threshold = 250 * (1024 * 1024);
if (leakedMemory > threshold) {
console.error(
`\n\n==========================================\n` +
`ERROR: Leaked ${MiB(leakedMemory)}, ` +
`which is more than the threshold of ${MiB(threshold)}. ` +
`Exiting with error code 1.` +
`\n==========================================\n\n`);
process.exit(1);
}
// TODO(rictic):
// looks like
// we've got
// a memory
// leak. Need
// to track
// this down.
// This
// should
// be <
// 10MiB,
// not <
// 100 MiB.
const threshold =
250 *
(1024 *
1024);
if (leakedMemory >
threshold) {
console.error(
`\n\n==========================================\n` +
`ERROR: Leaked ${MiB(
leakedMemory)}, ` +
`which is more than the threshold of ${MiB(
threshold)}. ` +
`Exiting with error code 1.` +
`\n==========================================\n\n`);
process
.exit(
1);
}
};

function printMeasurements(measurements: number[]) {
Expand All @@ -143,12 +162,11 @@ function printMeasurements(measurements: number[]) {
`);
console.log(
`${
padLeft(
'ms to analyze file that imports all polymer team\'s elements', 10)
padLeft('ms to analyze file that imports all polymer team\'s elements', 10)
}}`);
for (const elapsed of measurements) {
console.log(`${padLeft(elapsed.toFixed(0), 10)}`);
}
for (const elapsed of measurements) {
console.log(`${padLeft(elapsed.toFixed(0), 10)}`);
}
}

measure().catch(((err) => console.log(err.stack) && process.exit(1)));
5 changes: 3 additions & 2 deletions src/polymer/behavior-scanner.ts
Expand Up @@ -103,8 +103,9 @@ class BehaviorVisitor implements Visitor {
if (!name) {
this.currentBehavior.warnings.push({
code: 'cant-determine-name',
message: `Unable to determine property name from expression of type `
+ `${node.type}`,
message:
`Unable to determine property name from expression of type ` +
`${node.type}`,
severity: Severity.WARNING,
sourceRange: this.document.sourceRangeForNode(node)!
});
Expand Down
13 changes: 5 additions & 8 deletions src/polymer/declaration-property-handlers.ts
Expand Up @@ -33,14 +33,11 @@ export function getBehaviorAssignmentOrWarning(
document: JavaScriptDocument): BehaviorAssignmentOrWarning {
const behaviorName = astValue.getIdentifierName(argNode);
if (!behaviorName) {
return {
kind: 'warning',
warning: {
code: 'could-not-determine-behavior-name',
message:
`Could not determine behavior name from expression of type ${
argNode
.type
return {kind: 'warning', warning: {
code: 'could-not-determine-behavior-name',
message:
`Could not determine behavior name from expression of type ${
argNode.type
}`,
severity: Severity.WARNING,
sourceRange: document.sourceRangeForNode(argNode)!
Expand Down
5 changes: 2 additions & 3 deletions src/polymer/polymer-element-scanner.ts
Expand Up @@ -259,14 +259,13 @@ class ElementVisitor implements Visitor {
element.warnings.push({
message:
`Can't determine name for property key from expression with type ${
prop.key
.type
prop.key.type
}.`,
code: 'cant-determine-property-name',
severity: Severity.WARNING,
sourceRange: this.document.sourceRangeForNode(prop.key)!
});
continue;
continue;
}

if (!this.propertyHandlers) {
Expand Down
7 changes: 4 additions & 3 deletions src/polymer/polymer-element.ts
Expand Up @@ -181,9 +181,10 @@ export class ScannedPolymerElement extends ScannedElement implements
options.methods.forEach((m) => this.addMethod(m));
}
const summaryTag = jsdoc.getTag(this.jsdoc, 'summary');
this.summary = (summaryTag !== undefined && summaryTag.description != null)
? summaryTag.description
: '';
this.summary =
(summaryTag !== undefined && summaryTag.description != null) ?
summaryTag.description :
'';
}

addProperty(prop: ScannedPolymerProperty) {
Expand Down
11 changes: 7 additions & 4 deletions src/polymer/polymer2-mixin-scanner.ts
Expand Up @@ -95,8 +95,8 @@ export class MixinVisitor implements Visitor {
summary: (summaryTag && summaryTag.description) || '',
privacy: getOrInferPrivacy(namespacedName, nodeJsDocs, false),
jsdoc: nodeJsDocs,
mixins:
jsdoc.getMixinApplications(this._document, node, nodeJsDocs, this.warnings)
mixins: jsdoc.getMixinApplications(
this._document, node, nodeJsDocs, this.warnings)
});
this._currentMixinNode = node;
this.mixins.push(this._currentMixin);
Expand Down Expand Up @@ -211,10 +211,13 @@ export class MixinVisitor implements Visitor {

export function hasMixinFunctionDocTag(docs: jsdoc.Annotation) {
// TODO(justinfagnani): remove polymerMixin support
return (jsdoc.hasTag(docs, 'polymer') && jsdoc.hasTag(docs, 'mixinFunction')) || jsdoc.hasTag(docs, 'polymerMixin');
return (jsdoc.hasTag(docs, 'polymer') &&
jsdoc.hasTag(docs, 'mixinFunction')) ||
jsdoc.hasTag(docs, 'polymerMixin');
}

export function hasMixinClassDocTag(docs: jsdoc.Annotation) {
// TODO(justinfagnani): remove polymerMixinClass support
return (jsdoc.hasTag(docs, 'polymer') && jsdoc.hasTag(docs, 'mixinClass')) || jsdoc.hasTag(docs, 'polymerMixinClass');
return (jsdoc.hasTag(docs, 'polymer') && jsdoc.hasTag(docs, 'mixinClass')) ||
jsdoc.hasTag(docs, 'polymerMixinClass');
}
2 changes: 1 addition & 1 deletion src/scanning/scanner.ts
Expand Up @@ -33,5 +33,5 @@ export interface Scanner<D extends ParsedDocument<A, V>, A, V> {
}

export interface ScannerConstructor {
new(analyzer: Analyzer): Scanner<any, any, any>;
new (analyzer: Analyzer): Scanner<any, any, any>;
}
16 changes: 7 additions & 9 deletions src/test/analyzer_test.ts
Expand Up @@ -1001,15 +1001,13 @@ var DuplicateNamespace = {};
assert.deepEqual(document.url, 'base.html');
const localFeatures = document.getFeatures({imported: false});
const kinds = Array.from(localFeatures).map((f) => Array.from(f.kinds));
const message =
`localFeatures: ${
JSON.stringify(
Array.from(localFeatures)
.map((f) => ({
kinds: Array.from(f.kinds),
ids: Array.from(f.identifiers)
})))
}`;
const message = `localFeatures: ${
JSON.stringify(
Array.from(localFeatures).map((f) => ({
kinds: Array.from(f.kinds),
ids: Array.from(f.identifiers)
})))
}`;
assert.deepEqual(
kinds,
[
Expand Down
2 changes: 1 addition & 1 deletion src/test/core/dependency-graph_test.ts
Expand Up @@ -186,7 +186,7 @@ function assertGraphIsSettled(graph: DependencyGraph) {
false,
true,
`found unsettled record for url '${
record.url
record.url
}' in graph that should be settled`);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/javascript/jsdoc_test.ts
Expand Up @@ -16,7 +16,7 @@ import {assert} from 'chai';
import * as doctrine from 'doctrine';

import * as jsdoc from '../../javascript/jsdoc.js';
import { Privacy } from '../../model/model';
import {Privacy} from '../../model/model';

suite('jsdoc', () => {

Expand Down Expand Up @@ -75,7 +75,8 @@ suite('jsdoc', () => {
tags: [
{
title: 'param',
type: {type: 'NameExpression', name: 'Type'} as doctrine.type.NameExpression,
type: {type: 'NameExpression',
name: 'Type'} as doctrine.type.NameExpression,
name: 'name',
description: 'desc desc',
},
Expand Down

0 comments on commit 42909d1

Please sign in to comment.