Added code to sync __DEV__ value to RCT_DEBUG

Summary: @​public

When using bundled JS the `__DEV__` flag is set to false by default, which can cause errors to be missed if used for testing. This diff adds logic to override the `__DEV__` value when running in RCT_DEBUG configuration, so that the JS debug checks are enabled.

Reviewed By: @tadeuzagallo

Differential Revision: D2429533
This commit is contained in:
Nick Lockwood 2015-09-11 07:11:23 -07:00 committed by facebook-github-bot-9
parent 20cd649553
commit 789a07c5a4
1 changed files with 17 additions and 0 deletions

View File

@ -186,6 +186,23 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void);
RCTSourceLoadBlock onSourceLoad = ^(NSError *error, NSString *source) {
RCTProfileEndAsyncEvent(0, @"init,download", cookie, @"JavaScript download", nil);
RCTPerformanceLoggerEnd(RCTPLScriptDownload);
// Only override the value of __DEV__ if running in debug mode, and if we
// haven't explicitly overridden the packager dev setting in the bundleURL
BOOL shouldOverrideDev = RCT_DEBUG && ([self.bundleURL isFileURL] ||
[self.bundleURL.absoluteString rangeOfString:@"dev="].location == NSNotFound);
// Force JS __DEV__ value to match RCT_DEBUG
if (shouldOverrideDev) {
NSRange range = [source rangeOfString:@"__DEV__="];
RCTAssert(range.location != NSNotFound, @"It looks like the implementation"
"of __DEV__ has changed. Update -[RCTBatchedBridge loadSource:].");
NSRange valueRange = {range.location + range.length, 2};
if ([[source substringWithRange:valueRange] isEqualToString:@"!1"]) {
source = [source stringByReplacingCharactersInRange:valueRange withString:@" 1"];
}
}
_onSourceLoad(error, source);
};