Skip to content

Commit

Permalink
chore(types): upgrade to TypeScript 2.8.1 (#2304)
Browse files Browse the repository at this point in the history
This converts `externs.d.ts` to export a global namespace instead of a UMD global.

See: microsoft/TypeScript#22969

Fixes #2279.
  • Loading branch information
JoelEinbinder authored and aslushnikov committed Apr 4, 2018
1 parent 3b88d0d commit 2370618
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 40 deletions.
7 changes: 3 additions & 4 deletions lib/Puppeteer.js
Expand Up @@ -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<!Puppeteer.Browser>}
Expand Down Expand Up @@ -55,7 +55,6 @@ class Puppeteer {
static createBrowserFetcher(options) {
return new BrowserFetcher(options);
}
}
};

module.exports = Puppeteer;
helper.tracePublicAPI(Puppeteer);
helper.tracePublicAPI(module.exports, 'Puppeteer');
63 changes: 33 additions & 30 deletions lib/externs.d.ts
Expand Up @@ -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 {}
}
}
5 changes: 3 additions & 2 deletions lib/helper.js
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
}
}
13 changes: 10 additions & 3 deletions utils/doclint/check_public_api/JSBuilder.js
Expand Up @@ -19,19 +19,24 @@ 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<string, string>} */
this.inheritance = new Map();
this.errors = [];
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2370618

Please sign in to comment.