fix `$FlowFixMe`

Reviewed By: rafeca

Differential Revision: D6258938

fbshipit-source-id: 7331d0a3216c1714099139fe6c6ab8fe11771fae
This commit is contained in:
David Aurelio 2017-11-07 06:20:27 -08:00 committed by Facebook Github Bot
parent dbb2d44c42
commit 2c5a2fec66
15 changed files with 55 additions and 122 deletions

View File

@ -251,12 +251,9 @@ class Bundler {
return this._assetServer; return this._assetServer;
} }
end() { async end() {
this._transformer.kill(); this._transformer.kill();
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an await this._resolverPromise.then(resolver =>
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return this._resolverPromise.then(resolver =>
resolver resolver
.getDependencyGraph() .getDependencyGraph()
.getWatcher() .getWatcher()
@ -353,7 +350,7 @@ class Bundler {
}); });
} }
_bundle({ _bundle<T: Bundle | HMRBundle>({
assetPlugins, assetPlugins,
bundle, bundle,
dev, dev,
@ -372,7 +369,7 @@ class Bundler {
unbundle, unbundle,
}: { }: {
assetPlugins?: Array<string>, assetPlugins?: Array<string>,
bundle: Bundle | HMRBundle, bundle: T,
dev: boolean, dev: boolean,
entryFile?: string, entryFile?: string,
entryModuleOnly?: boolean, entryModuleOnly?: boolean,
@ -387,7 +384,7 @@ class Bundler {
runBeforeMainModule?: Array<string>, runBeforeMainModule?: Array<string>,
runModule?: boolean, runModule?: boolean,
unbundle?: boolean, unbundle?: boolean,
}) { }): Promise<T> {
const onResolutionResponse = ( const onResolutionResponse = (
response: ResolutionResponse<Module, BundlingOptions>, response: ResolutionResponse<Module, BundlingOptions>,
) => { ) => {
@ -463,7 +460,7 @@ class Bundler {
}); });
} }
_buildBundle({ _buildBundle<T: Bundle | HMRBundle>({
entryFile, entryFile,
dev, dev,
minify, minify,
@ -479,7 +476,7 @@ class Bundler {
onModuleTransformed = emptyFunction, onModuleTransformed = emptyFunction,
finalizeBundle = emptyFunction, finalizeBundle = emptyFunction,
onProgress = emptyFunction, onProgress = emptyFunction,
}: *) { }: *): Promise<T> {
const transformingFilesLogEntry = log( const transformingFilesLogEntry = log(
createActionStartEntry({ createActionStartEntry({
action_name: 'Transforming files', action_name: 'Transforming files',
@ -505,9 +502,6 @@ class Bundler {
}); });
} }
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return Promise.all([ return Promise.all([
this._resolverPromise, this._resolverPromise,
resolutionResponse, resolutionResponse,
@ -683,10 +677,7 @@ class Bundler {
+platform: string, +platform: string,
+minify: boolean, +minify: boolean,
+generateSourceMaps: boolean, +generateSourceMaps: boolean,
}) { }): Promise<Array<string>> {
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return this.getDependencies({ return this.getDependencies({
entryFile, entryFile,
rootEntryFile: entryFile, rootEntryFile: entryFile,
@ -698,7 +689,8 @@ class Bundler {
}).then(({dependencies}) => { }).then(({dependencies}) => {
const ret = []; const ret = [];
const promises = []; const promises = [];
const placeHolder = {}; /* $FlowFixMe: these are always removed */
const placeHolder: string = {};
dependencies.forEach(dep => { dependencies.forEach(dep => {
if (dep.isAsset()) { if (dep.isAsset()) {
const localPath = toLocalPath(this._projectRoots, dep.path); const localPath = toLocalPath(this._projectRoots, dep.path);

View File

@ -256,11 +256,8 @@ function* filter(iterator, predicate) {
} }
} }
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error class ArrayMap<K, V> extends Map<K, Array<V>> {
* found when Flow v0.54 was deployed. To see the error delete this comment and get(key: K): Array<V> {
* run Flow. */
class ArrayMap extends Map {
get(key) {
let array = super.get(key); let array = super.get(key);
if (!array) { if (!array) {
array = []; array = [];

View File

@ -138,11 +138,8 @@ export type ConfigT = {
runBeforeMainModule: Array<string>, runBeforeMainModule: Array<string>,
}; };
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an error
* found when Flow v0.56 was deployed. To see the error delete this comment and
* run Flow. */
const DEFAULT = ({ const DEFAULT = ({
extraNodeModules: Object.create(null), extraNodeModules: {},
getAssetExts: () => [], getAssetExts: () => [],
getBlacklistRE: () => blacklist(), getBlacklistRE: () => blacklist(),
getEnableBabelRCLookup: () => false, getEnableBabelRCLookup: () => false,

View File

@ -50,7 +50,10 @@ export type DeltaTransformResponse = {|
+pre: DeltaEntries, +pre: DeltaEntries,
+post: DeltaEntries, +post: DeltaEntries,
+delta: DeltaEntries, +delta: DeltaEntries,
+inverseDependencies: {[key: string]: $ReadOnlyArray<string>}, +inverseDependencies: {
[key: string]: $ReadOnlyArray<string>,
__proto__: null,
},
+reset: boolean, +reset: boolean,
|}; |};
@ -317,7 +320,7 @@ class DeltaTransformer extends EventEmitter {
*/ */
_getInverseDependencies( _getInverseDependencies(
dependencyEdges: DependencyEdges, dependencyEdges: DependencyEdges,
): {[key: string]: $ReadOnlyArray<string>} { ): {[key: string]: $ReadOnlyArray<string>, __proto__: null} {
const output = Object.create(null); const output = Object.create(null);
for (const [path, {inverseDependencies}] of dependencyEdges.entries()) { for (const [path, {inverseDependencies}] of dependencyEdges.entries()) {
@ -326,9 +329,6 @@ class DeltaTransformer extends EventEmitter {
).map(dep => this._getModuleId({path: dep})); ).map(dep => this._getModuleId({path: dep}));
} }
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
return output; return output;
} }

View File

@ -21,7 +21,11 @@ const path = require('path');
const util = require('util'); const util = require('util');
const workerFarm = require('../worker-farm'); const workerFarm = require('../worker-farm');
import type {Data as TransformData, Options as WorkerOptions} from './worker'; import type {
Data as TransformData,
Options as WorkerOptions,
TransformedCode,
} from './worker';
import type {LocalPath} from '../node-haste/lib/toLocalPath'; import type {LocalPath} from '../node-haste/lib/toLocalPath';
import type {MappingsMap} from '../lib/SourceMap'; import type {MappingsMap} from '../lib/SourceMap';
import typeof { import typeof {
@ -142,10 +146,7 @@ class Transformer {
kill() { kill() {
if (this._usesFarm && this._workers) { if (this._usesFarm && this._workers) {
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an workerFarm.end(this._workers, () => {});
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
workerFarm.end(this._workers);
} }
} }
@ -154,17 +155,12 @@ class Transformer {
localPath: LocalPath, localPath: LocalPath,
code: string, code: string,
options: WorkerOptions, options: WorkerOptions,
) { ): Promise<TransformedCode> {
if (!this._transform) { if (!this._transform) {
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return Promise.reject(new Error('No transform module')); return Promise.reject(new Error('No transform module'));
} }
debug('transforming file', fileName); debug('transforming file', fileName);
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return this._transform( return this._transform(
this._transformModulePath, this._transformModulePath,
fileName, fileName,

View File

@ -46,22 +46,19 @@ type ModuleDefinition = {|
isInitialized: boolean, isInitialized: boolean,
verboseName?: string, verboseName?: string,
|}; |};
type ModuleMap = {[key: ModuleID]: ModuleDefinition}; type ModuleMap = {[key: ModuleID]: ModuleDefinition, __proto__: null};
type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports; type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports;
type VerboseModuleNameForDev = string; type VerboseModuleNameForDev = string;
global.require = require; global.require = require;
global.__d = define; global.__d = define;
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an error
* found when Flow v0.56 was deployed. To see the error delete this comment and
* run Flow. */
const modules: ModuleMap = Object.create(null); const modules: ModuleMap = Object.create(null);
if (__DEV__) { if (__DEV__) {
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an error var verboseNamesToModuleIds: {
* found when Flow v0.56 was deployed. To see the error delete this comment [key: string]: number,
* and run Flow. */ __proto__: null,
var verboseNamesToModuleIds: {[key: string]: number} = Object.create(null); } = Object.create(null);
} }
function define( function define(

View File

@ -24,6 +24,7 @@ const formatBundlingError = require('../lib/formatBundlingError');
const getMaxWorkers = require('../lib/getMaxWorkers'); const getMaxWorkers = require('../lib/getMaxWorkers');
const getOrderedDependencyPaths = require('../lib/getOrderedDependencyPaths'); const getOrderedDependencyPaths = require('../lib/getOrderedDependencyPaths');
const mime = require('mime-types'); const mime = require('mime-types');
const nullthrows = require('fbjs/lib/nullthrows');
const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath');
const path = require('path'); const path = require('path');
const symbolicate = require('./symbolicate'); const symbolicate = require('./symbolicate');
@ -175,7 +176,7 @@ class Server {
workerPath: ?string, workerPath: ?string,
}; };
_projectRoots: $ReadOnlyArray<string>; _projectRoots: $ReadOnlyArray<string>;
_bundles: {}; _bundles: {__proto__: null};
_bundleBuildInfos: WeakMap<Bundle, BuildInfo>; _bundleBuildInfos: WeakMap<Bundle, BuildInfo>;
_changeWatchers: Array<{ _changeWatchers: Array<{
req: IncomingMessage, req: IncomingMessage,
@ -237,9 +238,6 @@ class Server {
this._reporter = reporter; this._reporter = reporter;
this._projectRoots = this._opts.projectRoots; this._projectRoots = this._opts.projectRoots;
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
this._bundles = Object.create(null); this._bundles = Object.create(null);
this._bundleBuildInfos = new WeakMap(); this._bundleBuildInfos = new WeakMap();
this._changeWatchers = []; this._changeWatchers = [];
@ -275,11 +273,9 @@ class Server {
for (const key in this._bundles) { for (const key in this._bundles) {
this._bundles[key] this._bundles[key]
.then(bundle => { .then(bundle => {
const deps = bundleDeps.get(bundle); const deps = nullthrows(bundleDeps.get(bundle));
filePaths.forEach(filePath => { filePaths.forEach(filePath => {
// $FlowFixMe(>=0.37.0)
if (deps.files.has(filePath)) { if (deps.files.has(filePath)) {
// $FlowFixMe(>=0.37.0)
deps.outdated.add(filePath); deps.outdated.add(filePath);
} }
}); });
@ -506,9 +502,6 @@ class Server {
} }
_clearBundles() { _clearBundles() {
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
this._bundles = Object.create(null); this._bundles = Object.create(null);
} }
@ -700,8 +693,7 @@ class Server {
if (optionsJson in this._bundles) { if (optionsJson in this._bundles) {
return this._bundles[optionsJson].then(bundle => { return this._bundles[optionsJson].then(bundle => {
const deps = bundleDeps.get(bundle); const deps = nullthrows(bundleDeps.get(bundle));
// $FlowFixMe(>=0.37.0)
const {dependencyPairs, files, idToIndex, outdated} = deps; const {dependencyPairs, files, idToIndex, outdated} = deps;
if (outdated.size) { if (outdated.size) {
const updatingExistingBundleLogEntry = log( const updatingExistingBundleLogEntry = log(
@ -713,7 +705,6 @@ class Server {
debug('Attempt to update existing bundle'); debug('Attempt to update existing bundle');
// $FlowFixMe(>=0.37.0)
deps.outdated = new Set(); deps.outdated = new Set();
const {platform, dev, minify, hot} = options; const {platform, dev, minify, hot} = options;

View File

@ -68,7 +68,7 @@ type Options<TModule, TPackage> = {|
|}; |};
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> { class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
_immediateResolutionCache: {[key: string]: TModule}; _immediateResolutionCache: {[key: string]: TModule, __proto__: null};
_options: Options<TModule, TPackage>; _options: Options<TModule, TPackage>;
static AmbiguousModuleResolutionError: Class<AmbiguousModuleResolutionError>; static AmbiguousModuleResolutionError: Class<AmbiguousModuleResolutionError>;
@ -146,7 +146,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
transformOptions: TransformWorkerOptions, transformOptions: TransformWorkerOptions,
onProgress?: ?(finishedModules: number, totalModules: number) => mixed, onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
recursive: boolean, recursive: boolean,
}) { }): Promise<void> {
const entry = this._options.moduleCache.getModule(this._options.entryPath); const entry = this._options.moduleCache.getModule(this._options.entryPath);
response.pushDependency(entry); response.pushDependency(entry);
@ -245,9 +245,6 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
return promise.then(value => [key, value]); return promise.then(value => [key, value]);
} }
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return Promise.all([ return Promise.all([
// kicks off recursive dependency discovery, but doesn't block until it's // kicks off recursive dependency discovery, but doesn't block until it's
// done // done
@ -363,13 +360,10 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
} }
_resetResolutionCache() { _resetResolutionCache() {
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
this._immediateResolutionCache = Object.create(null); this._immediateResolutionCache = Object.create(null);
} }
getResolutionCache(): {[key: string]: TModule} { getResolutionCache(): {[key: string]: TModule, __proto__: null} {
return this._immediateResolutionCache; return this._immediateResolutionCache;
} }
} }

View File

@ -24,7 +24,7 @@ class ResolutionResponse<TModule: {hash(): string}, TOptions> {
// This is monkey-patched from Resolver. // This is monkey-patched from Resolver.
getModuleId: ?() => number; getModuleId: ?() => number;
_mappings: {[hash: string]: Array<[string, TModule]>}; _mappings: {[hash: string]: Array<[string, TModule]>, __proto__: null};
_finalized: boolean; _finalized: boolean;
_mainModule: ?TModule; _mainModule: ?TModule;
@ -34,9 +34,6 @@ class ResolutionResponse<TModule: {hash(): string}, TOptions> {
this.mocks = null; this.mocks = null;
this.numPrependedDependencies = 0; this.numPrependedDependencies = 0;
this.options = options; this.options = options;
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
this._mappings = Object.create(null); this._mappings = Object.create(null);
this._finalized = false; this._finalized = false;
} }

View File

@ -144,18 +144,12 @@ class Module {
return this._getHasteName() != null; return this._getHasteName() != null;
} }
getCode(transformOptions: WorkerOptions) { async getCode(transformOptions: WorkerOptions): Promise<string> {
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an return (await this.read(transformOptions)).code;
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return this.read(transformOptions).then(({code}) => code);
} }
getMap(transformOptions: WorkerOptions) { async getMap(transformOptions: WorkerOptions) {
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an return (await this.read(transformOptions)).map;
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return this.read(transformOptions).then(({map}) => map);
} }
getName(): string { getName(): string {
@ -186,11 +180,8 @@ class Module {
return this._moduleCache.getPackageForModule(this); return this._moduleCache.getPackageForModule(this);
} }
getDependencies(transformOptions: WorkerOptions) { async getDependencies(transformOptions: WorkerOptions) {
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an return (await this.read(transformOptions)).dependencies;
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return this.read(transformOptions).then(({dependencies}) => dependencies);
} }
/** /**

View File

@ -33,9 +33,9 @@ class ModuleCache {
_getClosestPackage: GetClosestPackageFn; _getClosestPackage: GetClosestPackageFn;
_getTransformCacheKey: GetTransformCacheKey; _getTransformCacheKey: GetTransformCacheKey;
_globalTransformCache: ?GlobalTransformCache; _globalTransformCache: ?GlobalTransformCache;
_moduleCache: {[filePath: string]: Module}; _moduleCache: {[filePath: string]: Module, __proto__: null};
_moduleOptions: ModuleOptions; _moduleOptions: ModuleOptions;
_packageCache: {[filePath: string]: Package}; _packageCache: {[filePath: string]: Package, __proto__: null};
_packageModuleMap: WeakMap<Module, string>; _packageModuleMap: WeakMap<Module, string>;
_platforms: Set<string>; _platforms: Set<string>;
_transformCode: TransformCode; _transformCode: TransformCode;
@ -72,14 +72,8 @@ class ModuleCache {
this._getTransformCacheKey = getTransformCacheKey; this._getTransformCacheKey = getTransformCacheKey;
this._globalTransformCache = globalTransformCache; this._globalTransformCache = globalTransformCache;
this._depGraphHelpers = depGraphHelpers; this._depGraphHelpers = depGraphHelpers;
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
this._moduleCache = Object.create(null); this._moduleCache = Object.create(null);
this._moduleOptions = moduleOptions; this._moduleOptions = moduleOptions;
/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
this._packageCache = Object.create(null); this._packageCache = Object.create(null);
this._packageModuleMap = new WeakMap(); this._packageModuleMap = new WeakMap();
this._platforms = platforms; this._platforms = platforms;
@ -144,9 +138,8 @@ class ModuleCache {
} }
getPackageForModule(module: Module): ?Package { getPackageForModule(module: Module): ?Package {
if (this._packageModuleMap.has(module)) { let packagePath = this._packageModuleMap.get(module);
const packagePath = this._packageModuleMap.get(module); if (packagePath) {
// $FlowFixMe(>=0.37.0)
if (this._packageCache[packagePath]) { if (this._packageCache[packagePath]) {
return this._packageCache[packagePath]; return this._packageCache[packagePath];
} else { } else {
@ -154,7 +147,7 @@ class ModuleCache {
} }
} }
const packagePath = this._getClosestPackage(module.path); packagePath = this._getClosestPackage(module.path);
if (!packagePath) { if (!packagePath) {
return null; return null;
} }

View File

@ -43,11 +43,8 @@ class Polyfill extends Module {
return null; return null;
} }
getDependencies() { async getDependencies() {
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an return this._dependencies;
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
return Promise.resolve(this._dependencies);
} }
isJSON() { isJSON() {

View File

@ -40,10 +40,7 @@ function saveAsIndexedFile(
bundle: RamBundleInfo, bundle: RamBundleInfo,
options: OutputOptions, options: OutputOptions,
log: (...args: Array<string>) => void, log: (...args: Array<string>) => void,
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error ): Promise<mixed> {
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
): Promise<> {
const { const {
bundleOutput, bundleOutput,
bundleEncoding: encoding, bundleEncoding: encoding,

View File

@ -43,10 +43,7 @@ function saveUnbundle(
// overhead when reading hundreds pf assets from disk // overhead when reading hundreds pf assets from disk
return options.platform === 'android' && !options.indexedUnbundle return options.platform === 'android' && !options.indexedUnbundle
? asAssets(bundle, options, log) ? asAssets(bundle, options, log)
: /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an : asIndexedFile(bundle, options, log);
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
asIndexedFile(bundle, options, log);
} }
exports.build = buildBundle; exports.build = buildBundle;

View File

@ -17,10 +17,7 @@ function writeSourcemap(
fileName: string, fileName: string,
contents: string, contents: string,
log: (...args: Array<string>) => void, log: (...args: Array<string>) => void,
/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error ): Promise<mixed> {
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
): Promise<> {
if (!fileName) { if (!fileName) {
return Promise.resolve(); return Promise.resolve();
} }