Enforce object strictness at runtime

Reviewed By: jeanlauliac

Differential Revision: D7153674

fbshipit-source-id: a7f68d26430d04dc36360199ffcb243f8e2e09cf
This commit is contained in:
Miguel Jimenez Esun 2018-03-06 04:25:09 -08:00 committed by Facebook Github Bot
parent 08283058ec
commit 8a10127b58

View File

@ -103,6 +103,8 @@ export type Options = {|
+workerPath: ?string, +workerPath: ?string,
|}; |};
const {hasOwnProperty} = Object.prototype;
class Bundler { class Bundler {
_opts: Options; _opts: Options;
_cache: ?Cache<TransformedCode>; _cache: ?Cache<TransformedCode>;
@ -250,6 +252,27 @@ class Bundler {
// First, try getting the result from the cache if enabled. // First, try getting the result from the cache if enabled.
if (cache) { 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([ key = stableHash([
module.localPath, module.localPath,
code, code,
@ -257,16 +280,15 @@ class Bundler {
this._opts.assetRegistryPath, this._opts.assetRegistryPath,
this._opts.cacheVersion, this._opts.cacheVersion,
// We cannot include transformCodeOptions itself because of "rootPath". // We cannot include "transformCodeOptions" because of "projectRoot".
// This is also faster than using a destructuring. assetDataPlugins,
transformCodeOptions.assetDataPlugins, customTransformOptions,
transformCodeOptions.customTransformOptions, enableBabelRCLookup,
transformCodeOptions.enableBabelRCLookup, dev,
transformCodeOptions.dev, hot,
transformCodeOptions.hot, inlineRequires,
transformCodeOptions.inlineRequires, minify,
transformCodeOptions.minify, platform,
transformCodeOptions.platform,
]); ]);
result = await cache.get(key); result = await cache.get(key);