chore: upgrade to TypeScript 3.0.1 (#3024)

This commit is contained in:
Joel Einbinder 2018-08-06 11:31:33 -07:00 committed by Andrey Lushnikov
parent 25632133e2
commit 2e0007669d
16 changed files with 67 additions and 25 deletions

View File

@ -15,9 +15,9 @@
*/ */
const { helper, assert } = require('./helper'); const { helper, assert } = require('./helper');
const Target = require('./Target'); const {Target} = require('./Target');
const EventEmitter = require('events'); const EventEmitter = require('events');
const TaskQueue = require('./TaskQueue'); const {TaskQueue} = require('./TaskQueue');
class Browser extends EventEmitter { class Browser extends EventEmitter {
/** /**

View File

@ -80,5 +80,5 @@ Dialog.Type = {
Prompt: 'prompt' Prompt: 'prompt'
}; };
module.exports = Dialog; module.exports = {Dialog};
helper.tracePublicAPI(Dialog); helper.tracePublicAPI(Dialog);

View File

@ -389,5 +389,5 @@ function computeQuadArea(quad) {
return area; return area;
} }
module.exports = ElementHandle; module.exports = {ElementHandle};
helper.tracePublicAPI(ElementHandle); helper.tracePublicAPI(ElementHandle);

View File

@ -51,4 +51,4 @@ class EmulationManager {
} }
} }
module.exports = EmulationManager; module.exports = {EmulationManager};

View File

@ -100,7 +100,7 @@ class ExecutionContext {
/** /**
* @param {*} arg * @param {*} arg
* @return {*} * @return {*}
* @this {Frame} * @this {ExecutionContext}
*/ */
function convertArgument(arg) { function convertArgument(arg) {
if (Object.is(arg, -0)) if (Object.is(arg, -0))

View File

@ -18,7 +18,7 @@ const fs = require('fs');
const EventEmitter = require('events'); const EventEmitter = require('events');
const {helper, assert} = require('./helper'); const {helper, assert} = require('./helper');
const {ExecutionContext, JSHandle} = require('./ExecutionContext'); const {ExecutionContext, JSHandle} = require('./ExecutionContext');
const ElementHandle = require('./ElementHandle'); const {ElementHandle} = require('./ElementHandle');
const readFileAsync = helper.promisify(fs.readFile); const readFileAsync = helper.promisify(fs.readFile);

View File

@ -191,6 +191,7 @@ class Mouse {
this._keyboard = keyboard; this._keyboard = keyboard;
this._x = 0; this._x = 0;
this._y = 0; this._y = 0;
/** @type {'none'|'left'|'right'|'middle'} */
this._button = 'none'; this._button = 'none';
} }

View File

@ -13,12 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/**
* @template T
* @template V
*/
class Multimap { class Multimap {
constructor() { constructor() {
this._map = new Map(); this._map = new Map();
} }
/**
* @param {T} key
* @param {V} value
*/
set(key, value) { set(key, value) {
let set = this._map.get(key); let set = this._map.get(key);
if (!set) { if (!set) {
@ -28,6 +35,10 @@ class Multimap {
set.add(value); set.add(value);
} }
/**
* @param {T} key
* @return {!Set<V>}
*/
get(key) { get(key) {
let result = this._map.get(key); let result = this._map.get(key);
if (!result) if (!result)
@ -35,10 +46,19 @@ class Multimap {
return result; return result;
} }
/**
* @param {T} key
* @return {boolean}
*/
has(key) { has(key) {
return this._map.has(key); return this._map.has(key);
} }
/**
* @param {T} key
* @param {V} value
* @return {boolean}
*/
hasValue(key, value) { hasValue(key, value) {
const set = this._map.get(key); const set = this._map.get(key);
if (!set) if (!set)
@ -53,6 +73,11 @@ class Multimap {
return this._map.size; return this._map.size;
} }
/**
* @param {T} key
* @param {V} value
* @return {boolean}
*/
delete(key, value) { delete(key, value) {
const values = this.get(key); const values = this.get(key);
const result = values.delete(value); const result = values.delete(value);
@ -61,10 +86,17 @@ class Multimap {
return result; return result;
} }
/**
* @param {T} key
*/
deleteAll(key) { deleteAll(key) {
this._map.delete(key); this._map.delete(key);
} }
/**
* @param {T} key
* @return {V}
*/
firstValue(key) { firstValue(key) {
const set = this._map.get(key); const set = this._map.get(key);
if (!set) if (!set)
@ -72,10 +104,16 @@ class Multimap {
return set.values().next().value; return set.values().next().value;
} }
/**
* @return {T}
*/
firstKey() { firstKey() {
return this._map.keys().next().value; return this._map.keys().next().value;
} }
/**
* @return {!Array<V>}
*/
valuesArray() { valuesArray() {
const result = []; const result = [];
for (const key of this._map.keys()) for (const key of this._map.keys())
@ -83,6 +121,9 @@ class Multimap {
return result; return result;
} }
/**
* @return {!Array<T>}
*/
keysArray() { keysArray() {
return Array.from(this._map.keys()); return Array.from(this._map.keys());
} }

View File

@ -134,4 +134,4 @@ const puppeteerToProtocolLifecycle = {
'networkidle2': 'networkAlmostIdle', 'networkidle2': 'networkAlmostIdle',
}; };
module.exports = NavigatorWatcher; module.exports = {NavigatorWatcher};

View File

@ -41,9 +41,9 @@ class NetworkManager extends EventEmitter {
this._attemptedAuthentications = new Set(); this._attemptedAuthentications = new Set();
this._userRequestInterceptionEnabled = false; this._userRequestInterceptionEnabled = false;
this._protocolRequestInterceptionEnabled = false; this._protocolRequestInterceptionEnabled = false;
/** @type {!Multimap} */ /** @type {!Multimap<string, string>} */
this._requestHashToRequestIds = new Multimap(); this._requestHashToRequestIds = new Multimap();
/** @type {!Multimap} */ /** @type {!Multimap<string, string>} */
this._requestHashToInterceptionIds = new Multimap(); this._requestHashToInterceptionIds = new Multimap();
this._client.on('Network.requestWillBeSent', this._onRequestWillBeSent.bind(this)); this._client.on('Network.requestWillBeSent', this._onRequestWillBeSent.bind(this));

View File

@ -18,15 +18,15 @@ const fs = require('fs');
const EventEmitter = require('events'); const EventEmitter = require('events');
const mime = require('mime'); const mime = require('mime');
const {NetworkManager} = require('./NetworkManager'); const {NetworkManager} = require('./NetworkManager');
const NavigatorWatcher = require('./NavigatorWatcher'); const {NavigatorWatcher} = require('./NavigatorWatcher');
const Dialog = require('./Dialog'); const {Dialog} = require('./Dialog');
const EmulationManager = require('./EmulationManager'); const {EmulationManager} = require('./EmulationManager');
const {FrameManager} = require('./FrameManager'); const {FrameManager} = require('./FrameManager');
const {Keyboard, Mouse, Touchscreen} = require('./Input'); const {Keyboard, Mouse, Touchscreen} = require('./Input');
const Tracing = require('./Tracing'); const Tracing = require('./Tracing');
const {helper, debugError, assert} = require('./helper'); const {helper, debugError, assert} = require('./helper');
const {Coverage} = require('./Coverage'); const {Coverage} = require('./Coverage');
const Worker = require('./Worker'); const {Worker} = require('./Worker');
const writeFileAsync = helper.promisify(fs.writeFile); const writeFileAsync = helper.promisify(fs.writeFile);
@ -1194,5 +1194,5 @@ class ConsoleMessage {
} }
module.exports = Page; module.exports = {Page};
helper.tracePublicAPI(Page); helper.tracePublicAPI(Page);

View File

@ -1,4 +1,4 @@
const Page = require('./Page'); const {Page} = require('./Page');
const {helper} = require('./helper'); const {helper} = require('./helper');
class Target { class Target {
@ -102,4 +102,4 @@ class Target {
helper.tracePublicAPI(Target); helper.tracePublicAPI(Target);
module.exports = Target; module.exports = {Target};

View File

@ -14,4 +14,4 @@ class TaskQueue {
} }
} }
module.exports = TaskQueue; module.exports = {TaskQueue};

View File

@ -76,5 +76,5 @@ class Worker extends EventEmitter {
} }
} }
module.exports = Worker; module.exports = {Worker};
helper.tracePublicAPI(Worker); helper.tracePublicAPI(Worker);

8
lib/externs.d.ts vendored
View File

@ -1,12 +1,12 @@
import { Connection as RealConnection, CDPSession as RealCDPSession } from './Connection.js'; import { Connection as RealConnection, CDPSession as RealCDPSession } from './Connection.js';
import { Browser as RealBrowser, BrowserContext as RealBrowserContext} from './Browser.js'; import { Browser as RealBrowser, BrowserContext as RealBrowserContext} from './Browser.js';
import * as RealTarget from './Target.js'; import {Target as RealTarget} from './Target.js';
import * as RealPage from './Page.js'; import {Page as RealPage} from './Page.js';
import * as RealTaskQueue from './TaskQueue.js'; import {TaskQueue as RealTaskQueue} from './TaskQueue.js';
import {Mouse as RealMouse, Keyboard as RealKeyboard, Touchscreen as RealTouchscreen} from './Input.js'; import {Mouse as RealMouse, Keyboard as RealKeyboard, Touchscreen as RealTouchscreen} from './Input.js';
import {Frame as RealFrame, FrameManager as RealFrameManager} from './FrameManager.js'; import {Frame as RealFrame, FrameManager as RealFrameManager} from './FrameManager.js';
import {JSHandle as RealJSHandle, ExecutionContext as RealExecutionContext} from './ExecutionContext.js'; import {JSHandle as RealJSHandle, ExecutionContext as RealExecutionContext} from './ExecutionContext.js';
import * as RealElementHandle from './ElementHandle.js'; import {ElementHandle as RealElementHandle} from './ElementHandle.js';
import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js'; import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js';
import * as child_process from 'child_process'; import * as child_process from 'child_process';
declare global { declare global {

View File

@ -54,6 +54,6 @@
"pixelmatch": "^4.0.2", "pixelmatch": "^4.0.2",
"pngjs": "^3.3.3", "pngjs": "^3.3.3",
"text-diff": "^1.0.1", "text-diff": "^1.0.1",
"typescript": "~2.8.1" "typescript": "^3.0.1"
} }
} }