Fix react-native function call arity errors

Reviewed By: zertosh

Differential Revision: D5081816

fbshipit-source-id: 5978770c30a69fb287d03aa7511999ce30f856a1
This commit is contained in:
Gabe Levi 2017-05-18 16:51:37 -07:00 committed by Facebook Github Bot
parent aa3bbf18a1
commit 3ddc7d47d5
22 changed files with 86 additions and 72 deletions

View File

@ -24,7 +24,7 @@ var { TestModule } = ReactNative.NativeModules;
var deepDiffer = require('deepDiffer'); var deepDiffer = require('deepDiffer');
function debug() { function debug(...args) {
// console.log.apply(null, arguments); // console.log.apply(null, arguments);
} }

View File

@ -73,11 +73,15 @@ type Props = {
/** /**
* Rendered when the list is scrolled faster than rows can be rendered. * Rendered when the list is scrolled faster than rows can be rendered.
*/ */
renderWindowBoundaryIndicator?: () => ?React.Element<any>, renderWindowBoundaryIndicator?: (
showIndicator: boolean,
) => ?React.Element<any>,
/** /**
* Always rendered at the bottom of all the rows. * Always rendered at the bottom of all the rows.
*/ */
renderFooter?: () => ?React.Element<any>, renderFooter?: (
showFooter: boolean,
) => ?React.Element<any>,
/** /**
* Pipes through normal onScroll events from the underlying `ScrollView`. * Pipes through normal onScroll events from the underlying `ScrollView`.
*/ */

View File

@ -68,7 +68,13 @@ class MetroListView extends React.Component {
scrollToItem(params: {animated?: ?boolean, item: Item, viewPosition?: number}) { scrollToItem(params: {animated?: ?boolean, item: Item, viewPosition?: number}) {
throw new Error('scrollToItem not supported in legacy ListView.'); 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.'); throw new Error('scrollToLocation not supported in legacy ListView.');
} }
scrollToOffset(params: {animated?: ?boolean, offset: number}) { scrollToOffset(params: {animated?: ?boolean, offset: number}) {

View File

@ -40,7 +40,7 @@ type SectionBase = {
}, },
}) => ?React.Element<*>, }) => ?React.Element<*>,
ItemSeparatorComponent?: ?ReactClass<*>, ItemSeparatorComponent?: ?ReactClass<*>,
keyExtractor?: (item: SectionItem) => string, keyExtractor?: (item: SectionItem, index: ?number) => string,
// TODO: support more optional/override props // TODO: support more optional/override props
// FooterComponent?: ?ReactClass<*>, // FooterComponent?: ?ReactClass<*>,

View File

@ -60,7 +60,7 @@ if (__DEV__) {
'Each child in an array or iterator should have a unique ' + 'Each child in an array or iterator should have a unique ' +
'"key" prop. See https://fb.me/react-warning-keys for ' + '"key" prop. See https://fb.me/react-warning-keys for ' +
'more information.' + 'more information.' +
(getCurrentFiberStackAddendum(child) || ''); (getCurrentFiberStackAddendum() || '');
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
return; return;
} }
@ -71,7 +71,7 @@ if (__DEV__) {
'Each child in an array or iterator should have a unique ' + 'Each child in an array or iterator should have a unique ' +
'"key" prop. See https://fb.me/react-warning-keys for ' + '"key" prop. See https://fb.me/react-warning-keys for ' +
'more information.%s', 'more information.%s',
getCurrentFiberStackAddendum(child), getCurrentFiberStackAddendum(),
); );
}; };
} }

View File

@ -16,7 +16,7 @@ const invariant = require('fbjs/lib/invariant');
import type {CapturedError} from 'ReactFiberScheduler'; import type {CapturedError} from 'ReactFiberScheduler';
const defaultShowDialog = () => true; const defaultShowDialog = (capturedError: CapturedError) => true;
let showDialog = defaultShowDialog; let showDialog = defaultShowDialog;

View File

@ -49,7 +49,7 @@ type OpaqueRoot = FiberRoot;
export type HostConfig<T, P, I, TI, PI, C, CX, PL> = { export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
getRootHostContext(rootContainerInstance: C): CX, getRootHostContext(rootContainerInstance: C): CX,
getChildHostContext(parentHostContext: CX, type: T): CX, getChildHostContext(parentHostContext: CX, type: T, instance: C): CX,
getPublicInstance(instance: I | TI): PI, getPublicInstance(instance: I | TI): PI,
createInstance( createInstance(

View File

@ -452,7 +452,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
firstEffect = finishedWork.firstEffect; firstEffect = finishedWork.firstEffect;
} }
const commitInfo = prepareForCommit(); prepareForCommit();
// Commit all the side-effects within a tree. We'll do this in two passes. // 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 // The first pass performs all the host insertions, updates, deletions and
@ -468,11 +468,10 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
null, null,
commitAllHostEffects, commitAllHostEffects,
null, null,
finishedWork,
); );
} else { } else {
try { try {
commitAllHostEffects(finishedWork); commitAllHostEffects();
} catch (e) { } catch (e) {
error = e; error = e;
} }
@ -494,7 +493,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
stopCommitHostEffectsTimer(); stopCommitHostEffectsTimer();
} }
resetAfterCommit(commitInfo); resetAfterCommit();
// The work-in-progress tree is now the current tree. This must come after // 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 // the first pass of the commit phase, so that the previous tree is still
@ -517,11 +516,10 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
null, null,
commitAllLifeCycles, commitAllLifeCycles,
null, null,
finishedWork,
); );
} else { } else {
try { try {
commitAllLifeCycles(finishedWork); commitAllLifeCycles();
} catch (e) { } catch (e) {
error = e; error = e;
} }

View File

@ -28,10 +28,10 @@ var validateCallback = require('validateCallback');
* @implements PooledClass * @implements PooledClass
* @internal * @internal
*/ */
class CallbackQueue<T> { class CallbackQueue<T, Targ> {
_callbacks: ?Array<() => void>; _callbacks: ?Array<(arg: Targ) => void>;
_contexts: ?Array<T>; _contexts: ?Array<T>;
_arg: ?mixed; _arg: Targ;
constructor(arg) { constructor(arg) {
this._callbacks = null; this._callbacks = null;

View File

@ -95,8 +95,8 @@ var addPoolingTo = function<T>(
CopyConstructor: Class<T>, CopyConstructor: Class<T>,
pooler: Pooler, pooler: Pooler,
): Class<T> & { ): Class<T> & {
getPooled(): /* arguments of the constructor */ T, getPooled(...args: $ReadOnlyArray<mixed>): /* arguments of the constructor */ T,
release(): void, release(instance: mixed): void,
} { } {
// Casting as any so that flow ignores the actual implementation and trusts // Casting as any so that flow ignores the actual implementation and trusts
// it to match the type we declared // it to match the type we declared

View File

@ -16,12 +16,12 @@
* `console.error` as a failure callback - it's not properly bound. If passes an * `console.error` as a failure callback - it's not properly bound. If passes an
* `Error` object, it will print the message and stack. * `Error` object, it will print the message and stack.
*/ */
var logError = function() { var logError = function(...args: $ReadOnlyArray<mixed>) {
if (arguments.length === 1 && arguments[0] instanceof Error) { if (args.length === 1 && args[0] instanceof Error) {
var err = arguments[0]; var err = args[0];
console.error('Error: "' + err.message + '". Stack:\n' + err.stack); console.error('Error: "' + err.message + '". Stack:\n' + err.stack);
} else { } else {
console.error.apply(console, arguments); console.error.apply(console, args);
} }
}; };

View File

@ -26,6 +26,7 @@ declare module 'console' {
declare function trace(first: any, ...rest: any): void; declare function trace(first: any, ...rest: any): void;
declare function warn(...data: any): void; declare function warn(...data: any): void;
declare class Console { declare class Console {
constructor(stdout: stream$Writable, stdin?: stream$Writable): void;
assert(value: any, ...message: any): void, assert(value: any, ...message: any): void,
dir( dir(
obj: Object, obj: Object,

View File

@ -43,7 +43,7 @@ function createCodeWithMap(bundle: Bundle, dev: boolean, sourceMapSourcesRoot?:
function saveBundleAndMap( function saveBundleAndMap(
bundle: Bundle, bundle: Bundle,
options: OutputOptions, options: OutputOptions,
log: (x: string) => {}, log: (...args: Array<string>) => {},
): Promise<> { ): Promise<> {
const { const {
bundleOutput, bundleOutput,

View File

@ -38,7 +38,7 @@ const MODULES_DIR = 'js-modules';
function saveAsAssets( function saveAsAssets(
bundle: Bundle, bundle: Bundle,
options: OutputOptions, options: OutputOptions,
log: (x: string) => void, log: (...args: Array<string>) => void,
): Promise<mixed> { ): Promise<mixed> {
const { const {
bundleOutput, bundleOutput,

View File

@ -34,7 +34,7 @@ const SIZEOF_UINT32 = 4;
function saveAsIndexedFile( function saveAsIndexedFile(
bundle: Bundle, bundle: Bundle,
options: OutputOptions, options: OutputOptions,
log: (x: string) => void, log: (...args: Array<string>) => void,
): Promise<> { ): Promise<> {
const { const {
bundleOutput, bundleOutput,

View File

@ -15,7 +15,7 @@ const writeFile = require('../writeFile');
function writeSourcemap( function writeSourcemap(
fileName: string, fileName: string,
contents: string, contents: string,
log: (x: string) => void, log: (...args: Array<string>) => void,
): Promise<> { ): Promise<> {
if (!fileName) { if (!fileName) {
return Promise.resolve(); return Promise.resolve();

View File

@ -14,6 +14,7 @@
const assert = require('assert'); const assert = require('assert');
const crypto = require('crypto'); const crypto = require('crypto');
const debug = require('debug')('RNP:Bundler'); const debug = require('debug')('RNP:Bundler');
const emptyFunction = require('fbjs/lib/emptyFunction');
const fs = require('fs'); const fs = require('fs');
const Transformer = require('../JSTransformer'); const Transformer = require('../JSTransformer');
const Resolver = require('../Resolver'); const Resolver = require('../Resolver');
@ -89,8 +90,6 @@ export type ExtendedAssetDescriptor = AssetDescriptor & {
const sizeOf = denodeify(imageSize); const sizeOf = denodeify(imageSize);
const noop = () => {};
const { const {
createActionStartEntry, createActionStartEntry,
createActionEndEntry, createActionEndEntry,
@ -173,7 +172,7 @@ class Bundler {
this._getModuleId = createModuleIdFactory(); this._getModuleId = createModuleIdFactory();
let getCacheKey = () => ''; let getCacheKey = (options: mixed) => '';
if (opts.transformModulePath) { if (opts.transformModulePath) {
/* $FlowFixMe: dynamic requires prevent static typing :'( */ /* $FlowFixMe: dynamic requires prevent static typing :'( */
const transformer = require(opts.transformModulePath); const transformer = require(opts.transformModulePath);
@ -283,7 +282,7 @@ class Bundler {
const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root)); const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root));
if (!matchingRoot) { 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. // Replaces '\' with '/' for Windows paths.
@ -422,10 +421,10 @@ class Bundler {
isolateModuleIDs, isolateModuleIDs,
generateSourceMaps, generateSourceMaps,
assetPlugins, assetPlugins,
onResolutionResponse = noop, onResolutionResponse = emptyFunction,
onModuleTransformed = noop, onModuleTransformed = emptyFunction,
finalizeBundle = noop, finalizeBundle = emptyFunction,
onProgress = noop, onProgress = emptyFunction,
}: *) { }: *) {
const transformingFilesLogEntry = const transformingFilesLogEntry =
log(createActionStartEntry({ log(createActionStartEntry({
@ -641,7 +640,7 @@ class Bundler {
bundle: Bundle, bundle: Bundle,
entryFilePath: string, entryFilePath: string,
options: BundlingOptions, options: BundlingOptions,
getModuleId: () => number, getModuleId: (module: Module) => number,
dependencyPairs: Array<[string, Module]>, dependencyPairs: Array<[string, Module]>,
assetPlugins: Array<string>, assetPlugins: Array<string>,
}): Promise<ModuleTransport> { }): Promise<ModuleTransport> {

View File

@ -166,11 +166,11 @@ function TransformError() {
} }
util.inherits(TransformError, SyntaxError); util.inherits(TransformError, SyntaxError);
function formatError(err, filename, source) { function formatError(err, filename) {
if (err.loc) { if (err.loc) {
return formatBabelError(err, filename, source); return formatBabelError(err, filename);
} else { } else {
return formatGenericError(err, filename, source); return formatGenericError(err, filename);
} }
} }

View File

@ -10,6 +10,7 @@
*/ */
'use strict'; 'use strict';
const emptyFunction = require('fbjs/lib/emptyFunction');
const invariant = require('fbjs/lib/invariant'); const invariant = require('fbjs/lib/invariant');
const memoize = require('async/memoize'); const memoize = require('async/memoize');
const nullthrows = require('fbjs/lib/nullthrows'); const nullthrows = require('fbjs/lib/nullthrows');
@ -51,11 +52,10 @@ type LoadQueue =
const createParentModule = const createParentModule =
() => ({file: {code: '', type: 'script', path: ''}, dependencies: []}); () => ({file: {code: '', type: 'script', path: ''}, dependencies: []});
const noop = () => {};
const NO_OPTIONS = {}; const NO_OPTIONS = {};
exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn {
function Graph(entryPoints, platform, options, callback = noop) { function Graph(entryPoints, platform, options, callback = emptyFunction) {
const { const {
log = (console: any), log = (console: any),
optimize = false, optimize = false,
@ -80,7 +80,7 @@ exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn {
callback(null, collect()); callback(null, collect());
}; };
loadQueue.error = error => { loadQueue.error = error => {
loadQueue.error = noop; loadQueue.error = emptyFunction;
loadQueue.kill(); loadQueue.kill();
callback(error); callback(error);
}; };

View File

@ -16,6 +16,7 @@ const Bundler = require('../Bundler');
const MultipartResponse = require('./MultipartResponse'); const MultipartResponse = require('./MultipartResponse');
const defaults = require('../../defaults'); const defaults = require('../../defaults');
const emptyFunction = require('fbjs/lib/emptyFunction');
const mime = require('mime-types'); const mime = require('mime-types');
const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath');
const path = require('path'); const path = require('path');
@ -26,7 +27,6 @@ const url = require('url');
const debug = require('debug')('RNP:Server'); const debug = require('debug')('RNP:Server');
import type Module, {HasteImpl} from '../node-haste/Module'; import type Module, {HasteImpl} from '../node-haste/Module';
import type {Stats} from 'fs';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type Bundle from '../Bundler/Bundle'; import type Bundle from '../Bundler/Bundle';
@ -175,7 +175,7 @@ class Server {
watch: options.watch || false, watch: options.watch || false,
}; };
const processFileChange = const processFileChange =
({type, filePath, stat}) => this.onFileChange(type, filePath, stat); ({type, filePath}) => this.onFileChange(type, filePath);
this._reporter = options.reporter; this._reporter = options.reporter;
this._projectRoots = this._opts.projectRoots; this._projectRoots = this._opts.projectRoots;
@ -316,8 +316,8 @@ class Server {
}); });
} }
onFileChange(type: string, filePath: string, stat: Stats) { onFileChange(type: string, filePath: string) {
this._assetServer.onFileChange(type, filePath, stat); this._assetServer.onFileChange(type, filePath);
// If Hot Loading is enabled avoid rebuilding bundles and sending live // If Hot Loading is enabled avoid rebuilding bundles and sending live
// updates. Instead, send the HMR updates right away and clear the bundles // updates. Instead, send the HMR updates right away and clear the bundles
@ -653,7 +653,7 @@ class Server {
entry_point: options.entryFile, entry_point: options.entryFile,
})); }));
let reportProgress = () => {}; let reportProgress = emptyFunction;
if (!this._opts.silent) { if (!this._opts.silent) {
reportProgress = (transformedFileCount, totalFileCount) => { reportProgress = (transformedFileCount, totalFileCount) => {
this._reporter.update({ this._reporter.update({

View File

@ -90,14 +90,16 @@ class TransformCache {
* close to each others, one of the workers is going to loose its results no * close to each others, one of the workers is going to loose its results no
* matter what. * matter what.
*/ */
writeSync(props: { writeSync(
filePath: string, props: {
sourceCode: string, filePath: string,
getTransformCacheKey: GetTransformCacheKey, sourceCode: string,
transformOptions: WorkerOptions, getTransformCacheKey: GetTransformCacheKey,
transformOptionsKey: string, transformOptions: WorkerOptions,
result: CachedResult, transformOptionsKey: string,
}): void { result: CachedResult,
},
): void {
const cacheFilePath = this._getCacheFilePaths(props); const cacheFilePath = this._getCacheFilePaths(props);
mkdirp.sync(path.dirname(cacheFilePath.transformedCode)); mkdirp.sync(path.dirname(cacheFilePath.transformedCode));
const {result} = props; const {result} = props;
@ -233,7 +235,7 @@ class TransformCache {
mkdirp.sync(cacheDirPath); mkdirp.sync(cacheDirPath);
const cacheCollectionFilePath = path.join(cacheDirPath, 'last_collected'); const cacheCollectionFilePath = path.join(cacheDirPath, 'last_collected');
const lastCollected = Number.parseInt( const lastCollected = Number.parseInt(
tryReadFileSync(cacheCollectionFilePath, 'utf8'), tryReadFileSync(cacheCollectionFilePath),
10, 10,
); );
if ( if (
@ -253,10 +255,12 @@ class TransformCache {
* account because it would generate lots of file during development. (The * account because it would generate lots of file during development. (The
* source hash is stored in the metadata instead). * source hash is stored in the metadata instead).
*/ */
_getCacheFilePaths(props: { _getCacheFilePaths(
filePath: string, props: {
transformOptionsKey: string, filePath: string,
}): CacheFilePaths { transformOptionsKey: string,
},
): CacheFilePaths {
const hasher = crypto const hasher = crypto
.createHash('sha1') .createHash('sha1')
.update(props.filePath) .update(props.filePath)
@ -384,13 +388,15 @@ function tryParseJSON(str: string): any {
} }
} }
function hashSourceCode(props: { function hashSourceCode(
filePath: string, props: {
sourceCode: string, filePath: string,
getTransformCacheKey: GetTransformCacheKey, sourceCode: string,
transformOptions: WorkerOptions, getTransformCacheKey: GetTransformCacheKey,
transformOptionsKey: string, transformOptions: WorkerOptions,
}): string { transformOptionsKey: string,
},
): string {
return crypto return crypto
.createHash('sha1') .createHash('sha1')
.update(props.getTransformCacheKey(props.transformOptions)) .update(props.getTransformCacheKey(props.transformOptions))

View File

@ -156,8 +156,8 @@ class DependencyGraph extends EventEmitter {
this._filesByDirNameIndex = new FilesByDirNameIndex(hasteFS.getAllFiles()); this._filesByDirNameIndex = new FilesByDirNameIndex(hasteFS.getAllFiles());
this._assetResolutionCache.clear(); this._assetResolutionCache.clear();
this._moduleMap = moduleMap; this._moduleMap = moduleMap;
eventsQueue.forEach(({type, filePath, stat}) => eventsQueue.forEach(({type, filePath}) =>
this._moduleCache.processFileChange(type, filePath, stat) this._moduleCache.processFileChange(type, filePath)
); );
this.emit('change'); this.emit('change');
} }
@ -290,11 +290,11 @@ class DependencyGraph extends EventEmitter {
} }
function NotFoundError() { function NotFoundError(...args) {
/* $FlowFixMe: monkey-patching */ /* $FlowFixMe: monkey-patching */
Error.call(this); Error.call(this);
Error.captureStackTrace(this, this.constructor); Error.captureStackTrace(this, this.constructor);
var msg = util.format.apply(util, arguments); var msg = util.format.apply(util, args);
this.message = msg; this.message = msg;
this.type = this.name = 'NotFoundError'; this.type = this.name = 'NotFoundError';
this.status = 404; this.status = 404;