diff --git a/packager/react-packager/src/node-haste/AssetModule.js b/packager/react-packager/src/node-haste/AssetModule.js index 97e0c840b..21a12ef23 100644 --- a/packager/react-packager/src/node-haste/AssetModule.js +++ b/packager/react-packager/src/node-haste/AssetModule.js @@ -5,15 +5,26 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow */ + 'use strict'; const Module = require('./Module'); const getAssetDataFromName = require('./lib/getAssetDataFromName'); +import type {ConstructorArgs, ReadResult} from './Module'; + class AssetModule extends Module { - constructor(args, platforms) { + + resolution: mixed; + _name: string; + _type: string; + _dependencies: Array; + + constructor(args: ConstructorArgs & {dependencies: Array}, platforms: Set) { super(args); const { resolution, name, type } = getAssetDataFromName(this.path, platforms); this.resolution = resolution; @@ -30,7 +41,9 @@ class AssetModule extends Module { return Promise.resolve(this._dependencies); } - read() { + read(): Promise { + /** $FlowFixMe: improper OOP design. AssetModule, being different from a + * normal Module, shouldn't inherit it in the first place. */ return Promise.resolve({}); } diff --git a/packager/react-packager/src/node-haste/Module.js b/packager/react-packager/src/node-haste/Module.js index b4479ee07..43d4c3197 100644 --- a/packager/react-packager/src/node-haste/Module.js +++ b/packager/react-packager/src/node-haste/Module.js @@ -31,7 +31,7 @@ import type Cache from './Cache'; import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type ModuleCache from './ModuleCache'; -type ReadResult = { +export type ReadResult = { code: string, dependencies?: ?Array, dependencyOffsets?: ?Array, diff --git a/packager/react-packager/src/node-haste/ModuleCache.js b/packager/react-packager/src/node-haste/ModuleCache.js index 94358a3c4..193dac4df 100644 --- a/packager/react-packager/src/node-haste/ModuleCache.js +++ b/packager/react-packager/src/node-haste/ModuleCache.js @@ -28,7 +28,7 @@ type GetClosestPackageFn = (filePath: string) => ?string; class ModuleCache { - _assetDependencies: mixed; + _assetDependencies: Array; _cache: Cache; _depGraphHelpers: DependencyGraphHelpers; _getClosestPackage: GetClosestPackageFn; @@ -36,7 +36,7 @@ class ModuleCache { _moduleOptions: ModuleOptions; _packageCache: {[filePath: string]: Package}; _packageModuleMap: WeakMap; - _platforms: mixed; + _platforms: Set; _transformCacheKey: string; _transformCode: TransformCode; _reporter: Reporter; @@ -52,7 +52,7 @@ class ModuleCache { transformCode, reporter, }: { - assetDependencies: mixed, + assetDependencies: Array, cache: Cache, depGraphHelpers: DependencyGraphHelpers, getClosestPackage: GetClosestPackageFn, @@ -60,7 +60,7 @@ class ModuleCache { transformCacheKey: string, transformCode: TransformCode, reporter: Reporter, - }, platforms: mixed) { + }, platforms: Set) { this._assetDependencies = assetDependencies; this._getClosestPackage = getClosestPackage; this._cache = cache; @@ -97,6 +97,9 @@ class ModuleCache { getAssetModule(filePath: string) { if (!this._moduleCache[filePath]) { + /* $FlowFixMe: missing options. This is because this is an incorrect OOP + * design in the first place: AssetModule, being simpler than a normal + * Module, should not inherit the Module class. */ this._moduleCache[filePath] = new AssetModule({ file: filePath, moduleCache: this, diff --git a/packager/react-packager/src/node-haste/index.js b/packager/react-packager/src/node-haste/index.js index 13ded6d58..a37f96279 100644 --- a/packager/react-packager/src/node-haste/index.js +++ b/packager/react-packager/src/node-haste/index.js @@ -68,7 +68,7 @@ class DependencyGraph { useWatchman: boolean, watch: boolean, |}; - _assetDependencies: mixed; + _assetDependencies: Array; _cache: Cache; _haste: JestHasteMap; _hasteFS: HasteFS; @@ -103,7 +103,7 @@ class DependencyGraph { watch, reporter, }: { - assetDependencies: mixed, + assetDependencies: Array, assetExts: Array, cache: Cache, extensions?: ?Array,