From 8a10127b58761ed4dabe5b6239af09c459b6d6ad Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Tue, 6 Mar 2018 04:25:09 -0800 Subject: [PATCH] Enforce object strictness at runtime Reviewed By: jeanlauliac Differential Revision: D7153674 fbshipit-source-id: a7f68d26430d04dc36360199ffcb243f8e2e09cf --- packages/metro/src/Bundler/index.js | 42 ++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/packages/metro/src/Bundler/index.js b/packages/metro/src/Bundler/index.js index e174ae2a..554b95ee 100644 --- a/packages/metro/src/Bundler/index.js +++ b/packages/metro/src/Bundler/index.js @@ -103,6 +103,8 @@ export type Options = {| +workerPath: ?string, |}; +const {hasOwnProperty} = Object.prototype; + class Bundler { _opts: Options; _cache: ?Cache; @@ -250,6 +252,27 @@ class Bundler { // First, try getting the result from the cache if enabled. if (cache) { + const { + assetDataPlugins, + customTransformOptions, + enableBabelRCLookup, + dev, + hot, + inlineRequires, + minify, + platform, + projectRoot: _projectRoot, // Blacklisted property. + ...extra + } = transformCodeOptions; + + for (const key in extra) { + if (hasOwnProperty.call(extra, key)) { + throw new Error( + 'Extra keys detected: ' + Object.keys(extra).join(', '), + ); + } + } + key = stableHash([ module.localPath, code, @@ -257,16 +280,15 @@ class Bundler { this._opts.assetRegistryPath, this._opts.cacheVersion, - // We cannot include transformCodeOptions itself because of "rootPath". - // This is also faster than using a destructuring. - transformCodeOptions.assetDataPlugins, - transformCodeOptions.customTransformOptions, - transformCodeOptions.enableBabelRCLookup, - transformCodeOptions.dev, - transformCodeOptions.hot, - transformCodeOptions.inlineRequires, - transformCodeOptions.minify, - transformCodeOptions.platform, + // We cannot include "transformCodeOptions" because of "projectRoot". + assetDataPlugins, + customTransformOptions, + enableBabelRCLookup, + dev, + hot, + inlineRequires, + minify, + platform, ]); result = await cache.get(key);