From dfa05cbcd48e81baf4dd2a9af6e98d02d9690d60 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 5 Dec 2017 01:26:02 -0800 Subject: [PATCH] Enable flow type for a file and fix a related typo/bug Reviewed By: rafeca Differential Revision: D6473575 fbshipit-source-id: 7b96b6bfb2aff96e6d4697ad29fd96fb85d1ceda --- packages/metro/src/Bundler/index.js | 2 +- packages/metro/src/lib/createModuleIdFactory.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/metro/src/Bundler/index.js b/packages/metro/src/Bundler/index.js index 86e029a1..de5b659f 100644 --- a/packages/metro/src/Bundler/index.js +++ b/packages/metro/src/Bundler/index.js @@ -120,7 +120,7 @@ type Options = {| class Bundler { _opts: Options; - _getModuleId: ({path: string}) => number; + _getModuleId: (path: string) => number; _transformer: Transformer; _resolverPromise: Promise; _projectRoots: $ReadOnlyArray; diff --git a/packages/metro/src/lib/createModuleIdFactory.js b/packages/metro/src/lib/createModuleIdFactory.js index 76c5dbb7..5e57f79b 100644 --- a/packages/metro/src/lib/createModuleIdFactory.js +++ b/packages/metro/src/lib/createModuleIdFactory.js @@ -6,20 +6,22 @@ * 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 * @format */ 'use strict'; function createModuleIdFactory(): (path: string) => number { - const fileToIdMap = new Map(); + const fileToIdMap: Map = new Map(); let nextId = 0; return (path: string) => { - if (!fileToIdMap.has(path)) { - fileToIdMap.set(path, nextId); - nextId += 1; + let id = fileToIdMap.get(path); + if (typeof id !== 'number') { + id = nextId++; + fileToIdMap.set(path, id); } - return fileToIdMap.get(path); + return id; }; }