From be32cbef007dada23bf830b3b12df8beefbbdac6 Mon Sep 17 00:00:00 2001 From: Nikolai Tillmann Date: Fri, 27 Apr 2018 19:09:34 -0700 Subject: [PATCH] Make UIManager prepackable Reviewed By: sebmarkbage Differential Revision: D7736403 fbshipit-source-id: 6154b76d9d948658394488fe4472d8b5bbcd3d9f --- Libraries/ReactNative/UIManager.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Libraries/ReactNative/UIManager.js b/Libraries/ReactNative/UIManager.js index 9f34734a731..5f6c61619d9 100644 --- a/Libraries/ReactNative/UIManager.js +++ b/Libraries/ReactNative/UIManager.js @@ -77,11 +77,24 @@ if (Platform.OS === 'ios') { } }); } else if (UIManager.ViewManagerNames) { - UIManager.ViewManagerNames.forEach(viewManagerName => { - defineLazyObjectProperty(UIManager, viewManagerName, { - get: () => UIManager.getConstantsForViewManager(viewManagerName), + // We want to add all the view managers to the UIManager. + // However, the way things are set up, the list of view managers is not known at compile time. + // As Prepack runs at compile it, it cannot process this loop. + // So we wrap it in a special __residual call, which basically tells Prepack to ignore it. + let residual = global.__residual ? global.__residual : (_, f, ...args) => f.apply(undefined, args); + residual("void", (UIManager, defineLazyObjectProperty) => { + UIManager.ViewManagerNames.forEach(viewManagerName => { + defineLazyObjectProperty(UIManager, viewManagerName, { + get: () => UIManager.getConstantsForViewManager(viewManagerName), + }); }); - }); + }, UIManager, defineLazyObjectProperty); + + // As Prepack now no longer knows which properties exactly the UIManager has, + // we also tell Prepack that it has only partial knowledge of the UIManager, + // so that any accesses to unknown properties along the global code will fail + // when Prepack encounters them. + if (global.__makePartial) global.__makePartial(UIManager); } module.exports = UIManager;