From ae6cea6190fb1fd51441873e30f28c0064f14990 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 22 Apr 2020 11:05:58 +0100 Subject: [PATCH] Remove from externs file --- src/externs.d.ts | 4 --- utils/doclint/check_public_api/JSBuilder.js | 17 +++++++++- utils/doclint/check_public_api/index.js | 37 ++++++++++++++++++--- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/externs.d.ts b/src/externs.d.ts index 1a45f7a159785..78ee12ea0a0d0 100644 --- a/src/externs.d.ts +++ b/src/externs.d.ts @@ -1,16 +1,12 @@ import { Browser as RealBrowser, BrowserContext as RealBrowserContext} from './Browser.js'; import {Target as RealTarget} from './Target.js'; import {Page as RealPage} from './Page.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 {DOMWorld as RealDOMWorld} from './DOMWorld.js'; import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js'; import * as child_process from 'child_process'; declare global { module Puppeteer { - export class Mouse extends RealMouse {} - export class Keyboard extends RealKeyboard {} - export class Touchscreen extends RealTouchscreen {} export class Browser extends RealBrowser {} export class BrowserContext extends RealBrowserContext {} export class Target extends RealTarget {} diff --git a/utils/doclint/check_public_api/JSBuilder.js b/utils/doclint/check_public_api/JSBuilder.js index 420be53ca43ee..acf6d983f6f04 100644 --- a/utils/doclint/check_public_api/JSBuilder.js +++ b/utils/doclint/check_public_api/JSBuilder.js @@ -184,6 +184,15 @@ function checkSources(sources) { return new Documentation.Type(typeName, []); } + /** + * @param {!ts.Symbol} symbol + * @return {boolean} + */ + function symbolHasPrivateModifier(symbol) { + const modifiers = symbol.valueDeclaration.modifiers || []; + return modifiers.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword); + } + /** * @param {string} className * @param {!ts.Symbol} symbol @@ -194,8 +203,14 @@ function checkSources(sources) { const members = classEvents.get(className) || []; for (const [name, member] of symbol.members || []) { - if (name.startsWith('_')) + + /* Before TypeScript we denoted private methods with an underscore + * but in TypeScript we use the private keyword + * hence we check for either here. + */ + if (name.startsWith('_') || symbolHasPrivateModifier(member)) continue; + const memberType = checker.getTypeOfSymbolAtLocation(member, member.valueDeclaration); const signature = memberType.getCallSignatures()[0]; if (signature) diff --git a/utils/doclint/check_public_api/index.js b/utils/doclint/check_public_api/index.js index 5f2ba1f915658..7318988cc4c19 100644 --- a/utils/doclint/check_public_api/index.js +++ b/utils/doclint/check_public_api/index.js @@ -271,6 +271,30 @@ function compareDocumentations(actual, expected) { actualName: 'Object', expectedName: 'CommandParameters[T]' }], + ['Method ElementHandle.press() key', { + actualName: 'string', + expectedName: 'KeyInput' + }], + ['Method Keyboard.down() key', { + actualName: 'string', + expectedName: 'KeyInput' + }], + ['Method Keyboard.press() key', { + actualName: 'string', + expectedName: 'KeyInput' + }], + ['Method Keyboard.up() key', { + actualName: 'string', + expectedName: 'KeyInput' + }], + ['Method Mouse.down() options', { + actualName: 'Object', + expectedName: 'MouseOptions' + }], + ['Method Mouse.up() options', { + actualName: 'Object', + expectedName: 'MouseOptions' + }], ]); const expectedForSource = expectedNamingMismatches.get(source); @@ -295,12 +319,15 @@ function compareDocumentations(actual, expected) { const actualName = actual.name.replace(/[\? ]/g, ''); // TypeScript likes to add some spaces const expectedName = expected.name.replace(/\ /g, ''); - if (expectedName !== actualName) { - const namingMismatchIsExpected = namingMisMatchInTypeIsExpected(source, actualName, expectedName); + const namingMismatchIsExpected = namingMisMatchInTypeIsExpected(source, actualName, expectedName); + if (expectedName !== actualName && !namingMismatchIsExpected) + errors.push(`${source} ${actualName} != ${expectedName}`); - if (!namingMismatchIsExpected) - errors.push(`${source} ${actualName} != ${expectedName}`); - } + + /* If we got a naming mismatch and it was expected, don't check the properties + * as they will likely be considered "wrong" by DocLint too + */ + if (namingMismatchIsExpected) return; const actualPropertiesMap = new Map(actual.properties.map(property => [property.name, property.type])); const expectedPropertiesMap = new Map(expected.properties.map(property => [property.name, property.type])); const propertiesDiff = diff(Array.from(actualPropertiesMap.keys()).sort(), Array.from(expectedPropertiesMap.keys()).sort());