From 754e7015d97137fc1515f3de2654456d74e8c925 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 3 Jan 2017 09:53:33 -0800 Subject: [PATCH] packager: AssetModule: @flow Reviewed By: cpojer Differential Revision: D4377137 fbshipit-source-id: 991619c0a42319a3bb4bf28dab4dd0fe1a474def --- react-packager/src/node-haste/AssetModule.js | 17 +++++++++++++++-- react-packager/src/node-haste/Module.js | 2 +- react-packager/src/node-haste/ModuleCache.js | 11 +++++++---- react-packager/src/node-haste/index.js | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/react-packager/src/node-haste/AssetModule.js b/react-packager/src/node-haste/AssetModule.js index 97e0c840..21a12ef2 100644 --- a/react-packager/src/node-haste/AssetModule.js +++ b/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/react-packager/src/node-haste/Module.js b/react-packager/src/node-haste/Module.js index b4479ee0..43d4c319 100644 --- a/react-packager/src/node-haste/Module.js +++ b/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/react-packager/src/node-haste/ModuleCache.js b/react-packager/src/node-haste/ModuleCache.js index 94358a3c..193dac4d 100644 --- a/react-packager/src/node-haste/ModuleCache.js +++ b/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/react-packager/src/node-haste/index.js b/react-packager/src/node-haste/index.js index 13ded6d5..a37f9627 100644 --- a/react-packager/src/node-haste/index.js +++ b/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,