From 23706188192ce1f616ae29b50010eb560ca29da9 Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Wed, 4 Apr 2018 14:06:21 -0700 Subject: [PATCH] chore(types): upgrade to TypeScript 2.8.1 (#2304) This converts `externs.d.ts` to export a global namespace instead of a UMD global. See: https://github.com/Microsoft/TypeScript/issues/22969 Fixes #2279. --- lib/Puppeteer.js | 7 +-- lib/externs.d.ts | 63 +++++++++++---------- lib/helper.js | 5 +- package.json | 2 +- utils/doclint/check_public_api/JSBuilder.js | 13 ++++- 5 files changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/Puppeteer.js b/lib/Puppeteer.js index 59891cc4..9f673495 100644 --- a/lib/Puppeteer.js +++ b/lib/Puppeteer.js @@ -17,7 +17,7 @@ const {helper} = require('./helper'); const Launcher = require('./Launcher'); const BrowserFetcher = require('./BrowserFetcher'); -class Puppeteer { +module.exports = class { /** * @param {!Object=} options * @return {!Promise} @@ -55,7 +55,6 @@ class Puppeteer { static createBrowserFetcher(options) { return new BrowserFetcher(options); } -} +}; -module.exports = Puppeteer; -helper.tracePublicAPI(Puppeteer); +helper.tracePublicAPI(module.exports, 'Puppeteer'); diff --git a/lib/externs.d.ts b/lib/externs.d.ts index be6c175d..8fb7b02c 100644 --- a/lib/externs.d.ts +++ b/lib/externs.d.ts @@ -9,37 +9,40 @@ import {JSHandle as RealJSHandle, ExecutionContext as RealExecutionContext} fro import * as RealElementHandle from './ElementHandle.js'; import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js'; import * as child_process from 'child_process'; -export as namespace Puppeteer; +declare global { + module Puppeteer { + export class Connection extends RealConnection {} + export class CDPSession extends RealCDPSession {} + export class Mouse extends RealMouse {} + export class Keyboard extends RealKeyboard {} + export class Touchscreen extends RealTouchscreen {} + export class TaskQueue extends RealTaskQueue {} + export class Browser extends RealBrowser {} + export class Target extends RealTarget {} + export class Frame extends RealFrame {} + export class FrameManager extends RealFrameManager {} + export class NetworkManager extends RealNetworkManager {} + export class ElementHandle extends RealElementHandle {} + export class JSHandle extends RealJSHandle {} + export class ExecutionContext extends RealExecutionContext {} + export class Page extends RealPage { } + export class Response extends RealResponse { } + export class Request extends RealRequest { } -export class Connection extends RealConnection {} -export class CDPSession extends RealCDPSession {} -export class Mouse extends RealMouse {} -export class Keyboard extends RealKeyboard {} -export class Touchscreen extends RealTouchscreen {} -export class TaskQueue extends RealTaskQueue {} -export class Browser extends RealBrowser {} -export class Target extends RealTarget {} -export class Frame extends RealFrame {} -export class FrameManager extends RealFrameManager {} -export class NetworkManager extends RealNetworkManager {} -export class ElementHandle extends RealElementHandle {} -export class JSHandle extends RealJSHandle {} -export class ExecutionContext extends RealExecutionContext {} -export class Page extends RealPage { } -export class Response extends RealResponse { } -export class Request extends RealRequest { } + export interface ConnectionTransport extends NodeJS.EventEmitter { + send(string); + close(); + } -export interface ConnectionTransport extends NodeJS.EventEmitter { - send(string); - close(); -} + export interface TargetInfo { + type: string; + targetId: string; + title: string; + url: string; + attached: boolean; + } -export interface TargetInfo { - type: string; - targetId: string; - title: string; - url: string; - attached: boolean; -} + export interface ChildProcess extends child_process.ChildProcess {} -export interface ChildProcess extends child_process.ChildProcess {} + } +} \ No newline at end of file diff --git a/lib/helper.js b/lib/helper.js index f6e74765..ccaf42b7 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -112,9 +112,10 @@ class Helper { /** * @param {!Object} classType + * @param {string=} publicName */ - static tracePublicAPI(classType) { - let className = classType.prototype.constructor.name; + static tracePublicAPI(classType, publicName) { + let className = publicName || classType.prototype.constructor.name; className = className.substring(0, 1).toLowerCase() + className.substring(1); const debug = require('debug')(`puppeteer:${className}`); if (!debug.enabled && !apiCoverage) diff --git a/package.json b/package.json index 6968cf42..7a647ebb 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,6 @@ "pixelmatch": "^4.0.2", "pngjs": "^3.2.0", "text-diff": "^1.0.1", - "typescript": "~2.7.0" + "typescript": "~2.8.1" } } diff --git a/utils/doclint/check_public_api/JSBuilder.js b/utils/doclint/check_public_api/JSBuilder.js index 8bec50b3..1ff8b983 100644 --- a/utils/doclint/check_public_api/JSBuilder.js +++ b/utils/doclint/check_public_api/JSBuilder.js @@ -19,7 +19,11 @@ const ESTreeWalker = require('../../ESTreeWalker'); const Documentation = require('./Documentation'); class JSOutline { - constructor(text) { + /** + * @param {string} text + * @param {string} name + */ + constructor(text, name) { this.classes = []; /** @type {!Map} */ this.inheritance = new Map(); @@ -27,11 +31,12 @@ class JSOutline { this._eventsByClassName = new Map(); this._currentClassName = null; this._currentClassMembers = []; + this._name = name; this._text = text; const ast = esprima.parseScript(this._text, {loc: true, range: true}); const walker = new ESTreeWalker(node => { - if (node.type === 'ClassDeclaration') + if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') this._onClassDeclaration(node); else if (node.type === 'MethodDefinition') this._onMethodDefinition(node); @@ -46,6 +51,8 @@ class JSOutline { _onClassDeclaration(node) { this._flushClassIfNeeded(); this._currentClassName = this._extractText(node.id); + if (!this._currentClassName) + this._currentClassName = this._name.substring(0, this._name.indexOf('.')); const superClass = this._extractText(node.superClass); if (superClass) this.inheritance.set(this._currentClassName, superClass); @@ -179,7 +186,7 @@ module.exports = async function(sources) { const errors = []; const inheritance = new Map(); for (const source of sources) { - const outline = new JSOutline(source.text()); + const outline = new JSOutline(source.text(), source.name()); classes.push(...outline.classes); errors.push(...outline.errors); for (const entry of outline.inheritance)