From 3ddc7d47d5d7f043810a55227bf60bec823e7b02 Mon Sep 17 00:00:00 2001 From: Gabe Levi Date: Thu, 18 May 2017 16:51:37 -0700 Subject: [PATCH] Fix react-native function call arity errors Reviewed By: zertosh Differential Revision: D5081816 fbshipit-source-id: 5978770c30a69fb287d03aa7511999ce30f856a1 --- IntegrationTests/LayoutEventsTest.js | 2 +- Libraries/Experimental/WindowedListView.js | 8 +++- Libraries/Lists/MetroListView.js | 8 +++- Libraries/Lists/VirtualizedSectionList.js | 2 +- .../renderers/shared/fiber/ReactChildFiber.js | 4 +- .../shared/fiber/ReactFiberErrorLogger.js | 2 +- .../shared/fiber/ReactFiberReconciler.js | 2 +- .../shared/fiber/ReactFiberScheduler.js | 10 ++-- .../shared/stack/reconciler/CallbackQueue.js | 6 +-- .../Renderer/src/shared/utils/PooledClass.js | 4 +- Libraries/Utilities/logError.js | 8 ++-- flow/console.js | 1 + local-cli/bundle/output/bundle.js | 2 +- local-cli/bundle/output/unbundle/as-assets.js | 2 +- .../bundle/output/unbundle/as-indexed-file.js | 2 +- .../bundle/output/unbundle/write-sourcemap.js | 2 +- packager/src/Bundler/index.js | 17 ++++--- packager/src/JSTransformer/index.js | 6 +-- packager/src/ModuleGraph/Graph.js | 6 +-- packager/src/Server/index.js | 10 ++-- packager/src/lib/TransformCache.js | 46 +++++++++++-------- packager/src/node-haste/DependencyGraph.js | 8 ++-- 22 files changed, 86 insertions(+), 72 deletions(-) diff --git a/IntegrationTests/LayoutEventsTest.js b/IntegrationTests/LayoutEventsTest.js index a7c73ea7a..e8083e2f2 100644 --- a/IntegrationTests/LayoutEventsTest.js +++ b/IntegrationTests/LayoutEventsTest.js @@ -24,7 +24,7 @@ var { TestModule } = ReactNative.NativeModules; var deepDiffer = require('deepDiffer'); -function debug() { +function debug(...args) { // console.log.apply(null, arguments); } diff --git a/Libraries/Experimental/WindowedListView.js b/Libraries/Experimental/WindowedListView.js index c2e73c68d..c512adb73 100644 --- a/Libraries/Experimental/WindowedListView.js +++ b/Libraries/Experimental/WindowedListView.js @@ -73,11 +73,15 @@ type Props = { /** * Rendered when the list is scrolled faster than rows can be rendered. */ - renderWindowBoundaryIndicator?: () => ?React.Element, + renderWindowBoundaryIndicator?: ( + showIndicator: boolean, + ) => ?React.Element, /** * Always rendered at the bottom of all the rows. */ - renderFooter?: () => ?React.Element, + renderFooter?: ( + showFooter: boolean, + ) => ?React.Element, /** * Pipes through normal onScroll events from the underlying `ScrollView`. */ diff --git a/Libraries/Lists/MetroListView.js b/Libraries/Lists/MetroListView.js index 96f04ca22..508a020f7 100644 --- a/Libraries/Lists/MetroListView.js +++ b/Libraries/Lists/MetroListView.js @@ -68,7 +68,13 @@ class MetroListView extends React.Component { scrollToItem(params: {animated?: ?boolean, item: Item, viewPosition?: number}) { throw new Error('scrollToItem not supported in legacy ListView.'); } - scrollToLocation() { + scrollToLocation(params: { + animated?: ?boolean, + itemIndex: number, + sectionIndex: number, + viewOffset?: number, + viewPosition?: number, + }) { throw new Error('scrollToLocation not supported in legacy ListView.'); } scrollToOffset(params: {animated?: ?boolean, offset: number}) { diff --git a/Libraries/Lists/VirtualizedSectionList.js b/Libraries/Lists/VirtualizedSectionList.js index 52c49daaf..42b7e15b6 100644 --- a/Libraries/Lists/VirtualizedSectionList.js +++ b/Libraries/Lists/VirtualizedSectionList.js @@ -40,7 +40,7 @@ type SectionBase = { }, }) => ?React.Element<*>, ItemSeparatorComponent?: ?ReactClass<*>, - keyExtractor?: (item: SectionItem) => string, + keyExtractor?: (item: SectionItem, index: ?number) => string, // TODO: support more optional/override props // FooterComponent?: ?ReactClass<*>, diff --git a/Libraries/Renderer/src/renderers/shared/fiber/ReactChildFiber.js b/Libraries/Renderer/src/renderers/shared/fiber/ReactChildFiber.js index 3c1f06e91..147efd09d 100644 --- a/Libraries/Renderer/src/renderers/shared/fiber/ReactChildFiber.js +++ b/Libraries/Renderer/src/renderers/shared/fiber/ReactChildFiber.js @@ -60,7 +60,7 @@ if (__DEV__) { 'Each child in an array or iterator should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + - (getCurrentFiberStackAddendum(child) || ''); + (getCurrentFiberStackAddendum() || ''); if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { return; } @@ -71,7 +71,7 @@ if (__DEV__) { 'Each child in an array or iterator should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.%s', - getCurrentFiberStackAddendum(child), + getCurrentFiberStackAddendum(), ); }; } diff --git a/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberErrorLogger.js b/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberErrorLogger.js index 007be1a8b..9289f00a7 100644 --- a/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberErrorLogger.js +++ b/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberErrorLogger.js @@ -16,7 +16,7 @@ const invariant = require('fbjs/lib/invariant'); import type {CapturedError} from 'ReactFiberScheduler'; -const defaultShowDialog = () => true; +const defaultShowDialog = (capturedError: CapturedError) => true; let showDialog = defaultShowDialog; diff --git a/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberReconciler.js b/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberReconciler.js index 8d5c4faa7..a081838df 100644 --- a/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberReconciler.js +++ b/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberReconciler.js @@ -49,7 +49,7 @@ type OpaqueRoot = FiberRoot; export type HostConfig = { getRootHostContext(rootContainerInstance: C): CX, - getChildHostContext(parentHostContext: CX, type: T): CX, + getChildHostContext(parentHostContext: CX, type: T, instance: C): CX, getPublicInstance(instance: I | TI): PI, createInstance( diff --git a/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberScheduler.js b/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberScheduler.js index 844e19578..b889c8157 100644 --- a/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/Libraries/Renderer/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -452,7 +452,7 @@ module.exports = function( firstEffect = finishedWork.firstEffect; } - const commitInfo = prepareForCommit(); + prepareForCommit(); // Commit all the side-effects within a tree. We'll do this in two passes. // The first pass performs all the host insertions, updates, deletions and @@ -468,11 +468,10 @@ module.exports = function( null, commitAllHostEffects, null, - finishedWork, ); } else { try { - commitAllHostEffects(finishedWork); + commitAllHostEffects(); } catch (e) { error = e; } @@ -494,7 +493,7 @@ module.exports = function( stopCommitHostEffectsTimer(); } - resetAfterCommit(commitInfo); + resetAfterCommit(); // The work-in-progress tree is now the current tree. This must come after // the first pass of the commit phase, so that the previous tree is still @@ -517,11 +516,10 @@ module.exports = function( null, commitAllLifeCycles, null, - finishedWork, ); } else { try { - commitAllLifeCycles(finishedWork); + commitAllLifeCycles(); } catch (e) { error = e; } diff --git a/Libraries/Renderer/src/renderers/shared/stack/reconciler/CallbackQueue.js b/Libraries/Renderer/src/renderers/shared/stack/reconciler/CallbackQueue.js index c82dbfccd..0362598ac 100644 --- a/Libraries/Renderer/src/renderers/shared/stack/reconciler/CallbackQueue.js +++ b/Libraries/Renderer/src/renderers/shared/stack/reconciler/CallbackQueue.js @@ -28,10 +28,10 @@ var validateCallback = require('validateCallback'); * @implements PooledClass * @internal */ -class CallbackQueue { - _callbacks: ?Array<() => void>; +class CallbackQueue { + _callbacks: ?Array<(arg: Targ) => void>; _contexts: ?Array; - _arg: ?mixed; + _arg: Targ; constructor(arg) { this._callbacks = null; diff --git a/Libraries/Renderer/src/shared/utils/PooledClass.js b/Libraries/Renderer/src/shared/utils/PooledClass.js index a89b9e1a7..9055f4374 100644 --- a/Libraries/Renderer/src/shared/utils/PooledClass.js +++ b/Libraries/Renderer/src/shared/utils/PooledClass.js @@ -95,8 +95,8 @@ var addPoolingTo = function( CopyConstructor: Class, pooler: Pooler, ): Class & { - getPooled(): /* arguments of the constructor */ T, - release(): void, + getPooled(...args: $ReadOnlyArray): /* arguments of the constructor */ T, + release(instance: mixed): void, } { // Casting as any so that flow ignores the actual implementation and trusts // it to match the type we declared diff --git a/Libraries/Utilities/logError.js b/Libraries/Utilities/logError.js index aac41be0b..62a8d984e 100644 --- a/Libraries/Utilities/logError.js +++ b/Libraries/Utilities/logError.js @@ -16,12 +16,12 @@ * `console.error` as a failure callback - it's not properly bound. If passes an * `Error` object, it will print the message and stack. */ -var logError = function() { - if (arguments.length === 1 && arguments[0] instanceof Error) { - var err = arguments[0]; +var logError = function(...args: $ReadOnlyArray) { + if (args.length === 1 && args[0] instanceof Error) { + var err = args[0]; console.error('Error: "' + err.message + '". Stack:\n' + err.stack); } else { - console.error.apply(console, arguments); + console.error.apply(console, args); } }; diff --git a/flow/console.js b/flow/console.js index 793bb6cdc..c298bbe6d 100644 --- a/flow/console.js +++ b/flow/console.js @@ -26,6 +26,7 @@ declare module 'console' { declare function trace(first: any, ...rest: any): void; declare function warn(...data: any): void; declare class Console { + constructor(stdout: stream$Writable, stdin?: stream$Writable): void; assert(value: any, ...message: any): void, dir( obj: Object, diff --git a/local-cli/bundle/output/bundle.js b/local-cli/bundle/output/bundle.js index 0db6abd36..6d867dd07 100644 --- a/local-cli/bundle/output/bundle.js +++ b/local-cli/bundle/output/bundle.js @@ -43,7 +43,7 @@ function createCodeWithMap(bundle: Bundle, dev: boolean, sourceMapSourcesRoot?: function saveBundleAndMap( bundle: Bundle, options: OutputOptions, - log: (x: string) => {}, + log: (...args: Array) => {}, ): Promise<> { const { bundleOutput, diff --git a/local-cli/bundle/output/unbundle/as-assets.js b/local-cli/bundle/output/unbundle/as-assets.js index 43afcf7b0..8c167a0c4 100644 --- a/local-cli/bundle/output/unbundle/as-assets.js +++ b/local-cli/bundle/output/unbundle/as-assets.js @@ -38,7 +38,7 @@ const MODULES_DIR = 'js-modules'; function saveAsAssets( bundle: Bundle, options: OutputOptions, - log: (x: string) => void, + log: (...args: Array) => void, ): Promise { const { bundleOutput, diff --git a/local-cli/bundle/output/unbundle/as-indexed-file.js b/local-cli/bundle/output/unbundle/as-indexed-file.js index 7b7fb57ec..f8fbe8ac6 100644 --- a/local-cli/bundle/output/unbundle/as-indexed-file.js +++ b/local-cli/bundle/output/unbundle/as-indexed-file.js @@ -34,7 +34,7 @@ const SIZEOF_UINT32 = 4; function saveAsIndexedFile( bundle: Bundle, options: OutputOptions, - log: (x: string) => void, + log: (...args: Array) => void, ): Promise<> { const { bundleOutput, diff --git a/local-cli/bundle/output/unbundle/write-sourcemap.js b/local-cli/bundle/output/unbundle/write-sourcemap.js index 35af1b77b..18c05b2af 100644 --- a/local-cli/bundle/output/unbundle/write-sourcemap.js +++ b/local-cli/bundle/output/unbundle/write-sourcemap.js @@ -15,7 +15,7 @@ const writeFile = require('../writeFile'); function writeSourcemap( fileName: string, contents: string, - log: (x: string) => void, + log: (...args: Array) => void, ): Promise<> { if (!fileName) { return Promise.resolve(); diff --git a/packager/src/Bundler/index.js b/packager/src/Bundler/index.js index 38cf5ac09..b4e57d043 100644 --- a/packager/src/Bundler/index.js +++ b/packager/src/Bundler/index.js @@ -14,6 +14,7 @@ const assert = require('assert'); const crypto = require('crypto'); const debug = require('debug')('RNP:Bundler'); +const emptyFunction = require('fbjs/lib/emptyFunction'); const fs = require('fs'); const Transformer = require('../JSTransformer'); const Resolver = require('../Resolver'); @@ -89,8 +90,6 @@ export type ExtendedAssetDescriptor = AssetDescriptor & { const sizeOf = denodeify(imageSize); -const noop = () => {}; - const { createActionStartEntry, createActionEndEntry, @@ -173,7 +172,7 @@ class Bundler { this._getModuleId = createModuleIdFactory(); - let getCacheKey = () => ''; + let getCacheKey = (options: mixed) => ''; if (opts.transformModulePath) { /* $FlowFixMe: dynamic requires prevent static typing :'( */ const transformer = require(opts.transformModulePath); @@ -283,7 +282,7 @@ class Bundler { const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root)); if (!matchingRoot) { - throw new Error('No matching project root for ', filePath); + throw new Error('No matching project root for ' + filePath); } // Replaces '\' with '/' for Windows paths. @@ -422,10 +421,10 @@ class Bundler { isolateModuleIDs, generateSourceMaps, assetPlugins, - onResolutionResponse = noop, - onModuleTransformed = noop, - finalizeBundle = noop, - onProgress = noop, + onResolutionResponse = emptyFunction, + onModuleTransformed = emptyFunction, + finalizeBundle = emptyFunction, + onProgress = emptyFunction, }: *) { const transformingFilesLogEntry = log(createActionStartEntry({ @@ -641,7 +640,7 @@ class Bundler { bundle: Bundle, entryFilePath: string, options: BundlingOptions, - getModuleId: () => number, + getModuleId: (module: Module) => number, dependencyPairs: Array<[string, Module]>, assetPlugins: Array, }): Promise { diff --git a/packager/src/JSTransformer/index.js b/packager/src/JSTransformer/index.js index 7b23fd1f4..66a96b8f1 100644 --- a/packager/src/JSTransformer/index.js +++ b/packager/src/JSTransformer/index.js @@ -166,11 +166,11 @@ function TransformError() { } util.inherits(TransformError, SyntaxError); -function formatError(err, filename, source) { +function formatError(err, filename) { if (err.loc) { - return formatBabelError(err, filename, source); + return formatBabelError(err, filename); } else { - return formatGenericError(err, filename, source); + return formatGenericError(err, filename); } } diff --git a/packager/src/ModuleGraph/Graph.js b/packager/src/ModuleGraph/Graph.js index e8079139a..4e5236a09 100644 --- a/packager/src/ModuleGraph/Graph.js +++ b/packager/src/ModuleGraph/Graph.js @@ -10,6 +10,7 @@ */ 'use strict'; +const emptyFunction = require('fbjs/lib/emptyFunction'); const invariant = require('fbjs/lib/invariant'); const memoize = require('async/memoize'); const nullthrows = require('fbjs/lib/nullthrows'); @@ -51,11 +52,10 @@ type LoadQueue = const createParentModule = () => ({file: {code: '', type: 'script', path: ''}, dependencies: []}); -const noop = () => {}; const NO_OPTIONS = {}; exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { - function Graph(entryPoints, platform, options, callback = noop) { + function Graph(entryPoints, platform, options, callback = emptyFunction) { const { log = (console: any), optimize = false, @@ -80,7 +80,7 @@ exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { callback(null, collect()); }; loadQueue.error = error => { - loadQueue.error = noop; + loadQueue.error = emptyFunction; loadQueue.kill(); callback(error); }; diff --git a/packager/src/Server/index.js b/packager/src/Server/index.js index fae8323b7..db2d10b8c 100644 --- a/packager/src/Server/index.js +++ b/packager/src/Server/index.js @@ -16,6 +16,7 @@ const Bundler = require('../Bundler'); const MultipartResponse = require('./MultipartResponse'); const defaults = require('../../defaults'); +const emptyFunction = require('fbjs/lib/emptyFunction'); const mime = require('mime-types'); const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); const path = require('path'); @@ -26,7 +27,6 @@ const url = require('url'); const debug = require('debug')('RNP:Server'); import type Module, {HasteImpl} from '../node-haste/Module'; -import type {Stats} from 'fs'; import type {IncomingMessage, ServerResponse} from 'http'; import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import type Bundle from '../Bundler/Bundle'; @@ -175,7 +175,7 @@ class Server { watch: options.watch || false, }; const processFileChange = - ({type, filePath, stat}) => this.onFileChange(type, filePath, stat); + ({type, filePath}) => this.onFileChange(type, filePath); this._reporter = options.reporter; this._projectRoots = this._opts.projectRoots; @@ -316,8 +316,8 @@ class Server { }); } - onFileChange(type: string, filePath: string, stat: Stats) { - this._assetServer.onFileChange(type, filePath, stat); + onFileChange(type: string, filePath: string) { + this._assetServer.onFileChange(type, filePath); // If Hot Loading is enabled avoid rebuilding bundles and sending live // updates. Instead, send the HMR updates right away and clear the bundles @@ -653,7 +653,7 @@ class Server { entry_point: options.entryFile, })); - let reportProgress = () => {}; + let reportProgress = emptyFunction; if (!this._opts.silent) { reportProgress = (transformedFileCount, totalFileCount) => { this._reporter.update({ diff --git a/packager/src/lib/TransformCache.js b/packager/src/lib/TransformCache.js index eb98342ac..d32189b87 100644 --- a/packager/src/lib/TransformCache.js +++ b/packager/src/lib/TransformCache.js @@ -90,14 +90,16 @@ class TransformCache { * close to each others, one of the workers is going to loose its results no * matter what. */ - writeSync(props: { - filePath: string, - sourceCode: string, - getTransformCacheKey: GetTransformCacheKey, - transformOptions: WorkerOptions, - transformOptionsKey: string, - result: CachedResult, - }): void { + writeSync( + props: { + filePath: string, + sourceCode: string, + getTransformCacheKey: GetTransformCacheKey, + transformOptions: WorkerOptions, + transformOptionsKey: string, + result: CachedResult, + }, + ): void { const cacheFilePath = this._getCacheFilePaths(props); mkdirp.sync(path.dirname(cacheFilePath.transformedCode)); const {result} = props; @@ -233,7 +235,7 @@ class TransformCache { mkdirp.sync(cacheDirPath); const cacheCollectionFilePath = path.join(cacheDirPath, 'last_collected'); const lastCollected = Number.parseInt( - tryReadFileSync(cacheCollectionFilePath, 'utf8'), + tryReadFileSync(cacheCollectionFilePath), 10, ); if ( @@ -253,10 +255,12 @@ class TransformCache { * account because it would generate lots of file during development. (The * source hash is stored in the metadata instead). */ - _getCacheFilePaths(props: { - filePath: string, - transformOptionsKey: string, - }): CacheFilePaths { + _getCacheFilePaths( + props: { + filePath: string, + transformOptionsKey: string, + }, + ): CacheFilePaths { const hasher = crypto .createHash('sha1') .update(props.filePath) @@ -384,13 +388,15 @@ function tryParseJSON(str: string): any { } } -function hashSourceCode(props: { - filePath: string, - sourceCode: string, - getTransformCacheKey: GetTransformCacheKey, - transformOptions: WorkerOptions, - transformOptionsKey: string, -}): string { +function hashSourceCode( + props: { + filePath: string, + sourceCode: string, + getTransformCacheKey: GetTransformCacheKey, + transformOptions: WorkerOptions, + transformOptionsKey: string, + }, +): string { return crypto .createHash('sha1') .update(props.getTransformCacheKey(props.transformOptions)) diff --git a/packager/src/node-haste/DependencyGraph.js b/packager/src/node-haste/DependencyGraph.js index 7516bc8f1..ff049c984 100644 --- a/packager/src/node-haste/DependencyGraph.js +++ b/packager/src/node-haste/DependencyGraph.js @@ -156,8 +156,8 @@ class DependencyGraph extends EventEmitter { this._filesByDirNameIndex = new FilesByDirNameIndex(hasteFS.getAllFiles()); this._assetResolutionCache.clear(); this._moduleMap = moduleMap; - eventsQueue.forEach(({type, filePath, stat}) => - this._moduleCache.processFileChange(type, filePath, stat) + eventsQueue.forEach(({type, filePath}) => + this._moduleCache.processFileChange(type, filePath) ); this.emit('change'); } @@ -290,11 +290,11 @@ class DependencyGraph extends EventEmitter { } -function NotFoundError() { +function NotFoundError(...args) { /* $FlowFixMe: monkey-patching */ Error.call(this); Error.captureStackTrace(this, this.constructor); - var msg = util.format.apply(util, arguments); + var msg = util.format.apply(util, args); this.message = msg; this.type = this.name = 'NotFoundError'; this.status = 404;