diff --git a/.eslintrc b/.eslintrc index 84045365c85b89..e1ec93029f2bd1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,19 @@ { + "parser": "babel-eslint", + + "ecmaFeatures": { + "jsx": true + }, + "env": { + "es6": true, "jasmine": true, }, + "plugins": [ + "react" + ], + // Map from global var to bool specifying if it can be redefined "globals": { "__DEV__": true, @@ -36,10 +47,10 @@ }, "rules": { + "comma-dangle": 0, // disallow trailing commas in object literals "no-cond-assign": 1, // disallow assignment in conditional expressions "no-console": 0, // disallow use of console (off by default in the node environment) "no-constant-condition": 0, // disallow use of constant expressions in conditions - "no-comma-dangle": 0, // disallow trailing commas in object literals "no-control-regex": 1, // disallow control characters in regular expressions "no-debugger": 1, // disallow use of debugger "no-dupe-keys": 1, // disallow duplicate keys when creating object literals @@ -107,6 +118,7 @@ "no-warning-comments": 0, // disallow usage of configurable warning terms in comments": 1, // e.g. TODO or FIXME (off by default) "no-with": 1, // disallow use of the with statement "radix": 1, // require use of the second argument for parseInt() (off by default) + "semi-spacing": 1, // require a space after a semi-colon "vars-on-top": 0, // requires to declare all vars on top of their containing scope (off by default) "wrap-iife": 0, // require immediate function invocation to be wrapped in parentheses (off by default) "yoda": 1, // require or disallow Yoda conditions @@ -177,7 +189,7 @@ "space-in-parens": 0, // require or disallow spaces inside parentheses (off by default) "space-infix-ops": 1, // require spaces around operators "space-return-throw-case": 1, // require a space after return, throw, and case - "space-unary-word-ops": 1, // require a space around word operators such as typeof (off by default) + "space-unary-ops": [1, { "words": true, "nonwords": false }], // require or disallow spaces before/after unary operators (words on by default, nonwords off by default) "max-nested-callbacks": 0, // specify the maximum depth callbacks can be nested (off by default) "one-var": 0, // allow just one var statement per function (off by default) "wrap-regex": 0, // require regex literals to be wrapped in parentheses (off by default) @@ -190,6 +202,22 @@ "max-params": 0, // limits the number of parameters that can be used in the function declaration. (off by default) "max-statements": 0, // specify the maximum number of statement allowed in a function (off by default) "no-bitwise": 1, // disallow use of bitwise operators (off by default) - "no-plusplus": 0 // disallow use of unary operators, ++ and -- (off by default) + "no-plusplus": 0, // disallow use of unary operators, ++ and -- (off by default) + + "react/display-name": 0, + "react/jsx-boolean-value": 0, + "react/jsx-quotes": [1, "double", "avoid-escape"], + "react/jsx-no-undef": 1, + "react/jsx-sort-props": 0, + "react/jsx-uses-react": 0, + "react/jsx-uses-vars": 1, + "react/no-did-mount-set-state": [1, "allow-in-func"], + "react/no-did-update-set-state": [1, "allow-in-func"], + "react/no-multi-comp": 0, + "react/no-unknown-property": 0, + "react/prop-types": 0, + "react/react-in-jsx-scope": 0, + "react/self-closing-comp": 1, + "react/wrap-multilines": 0 } } diff --git a/.gitignore b/.gitignore index ed8c09532e8c3d..f82c4f157f409b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ project.xcworkspace # Node node_modules +*.log diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6bb19e007ba308..fbee3c875eb0f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,8 +19,8 @@ The core team will be monitoring for pull requests. When we get one, we'll run s 1. Fork the repo and create your branch from `master`. 2. If you've added code that should be tested, add tests! 3. If you've changed APIs, update the documentation. -4. Ensure the test suite passes. -5. Make sure your code lints - we've done our best to make sure these rules match our internal linting guidelines. +4. Ensure tests pass on Travis. +5. Make sure your code lints (`node linter.js `). 6. If you haven't already, complete the CLA. ### Contributor License Agreement ("CLA") diff --git a/Examples/SampleApp/_flowconfig b/Examples/SampleApp/_flowconfig index 9d4fb361444f83..a86e0f89c69951 100644 --- a/Examples/SampleApp/_flowconfig +++ b/Examples/SampleApp/_flowconfig @@ -31,3 +31,6 @@ node_modules/react-native/Libraries/react-native/react-native-interface.js [options] module.system=haste + +[version] +0.11.0 diff --git a/Examples/UIExplorer/AppStateIOSExample.js b/Examples/UIExplorer/AppStateIOSExample.js index 9272f9e7830197..c2a011ceba96b8 100644 --- a/Examples/UIExplorer/AppStateIOSExample.js +++ b/Examples/UIExplorer/AppStateIOSExample.js @@ -28,13 +28,19 @@ var AppStateSubscription = React.createClass({ return { appState: AppStateIOS.currentState, previousAppStates: [], + memoryWarnings: 0, }; }, componentDidMount: function() { AppStateIOS.addEventListener('change', this._handleAppStateChange); + AppStateIOS.addEventListener('memoryWarning', this._handleMemoryWarning); }, componentWillUnmount: function() { AppStateIOS.removeEventListener('change', this._handleAppStateChange); + AppStateIOS.removeEventListener('memoryWarning', this._handleMemoryWarning); + }, + _handleMemoryWarning: function() { + this.setState({memoryWarnings: this.state.memoryWarnings + 1}) }, _handleAppStateChange: function(appState) { var previousAppStates = this.state.previousAppStates.slice(); @@ -45,6 +51,13 @@ var AppStateSubscription = React.createClass({ }); }, render() { + if (this.props.showMemoryWarnings) { + return ( + + {this.state.memoryWarnings} + + ); + } if (this.props.showCurrentOnly) { return ( @@ -77,4 +90,9 @@ exports.examples = [ title: 'Previous states:', render(): ReactElement { return ; } }, + { + title: 'Memory Warnings', + description: "In the simulator, hit Shift+Command+M to simulate a memory warning.", + render(): ReactElement { return ; } + }, ]; diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testLayoutExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testLayoutExampleSnapshot_1@2x.png index a1789c7914b5cd..e99f0e63b14188 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testLayoutExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testLayoutExampleSnapshot_1@2x.png differ diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSliderExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSliderExampleSnapshot_1@2x.png index bf6fa1f9f76b7a..3abba045594e2b 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSliderExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSliderExampleSnapshot_1@2x.png differ diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSwitchExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSwitchExampleSnapshot_1@2x.png index 3ff3cef9e45888..2815f3e2d4e773 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSwitchExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testSwitchExampleSnapshot_1@2x.png differ diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTabBarExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTabBarExampleSnapshot_1@2x.png index 6fa9c155577050..1d7d2c479eb760 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTabBarExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTabBarExampleSnapshot_1@2x.png differ diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png index edde59bcc1c07f..77e3bda6e3b85d 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testTextExampleSnapshot_1@2x.png differ diff --git a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testViewExampleSnapshot_1@2x.png b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testViewExampleSnapshot_1@2x.png index 161ddba986f281..ad1f14b63d782b 100644 Binary files a/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testViewExampleSnapshot_1@2x.png and b/Examples/UIExplorer/UIExplorerTests/ReferenceImages/Examples-UIExplorer-UIExplorerApp/testViewExampleSnapshot_1@2x.png differ diff --git a/Libraries/AppStateIOS/AppStateIOS.ios.js b/Libraries/AppStateIOS/AppStateIOS.ios.js index 48db8415b9201a..b11c41a53694af 100644 --- a/Libraries/AppStateIOS/AppStateIOS.ios.js +++ b/Libraries/AppStateIOS/AppStateIOS.ios.js @@ -16,10 +16,12 @@ var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); var RCTAppState = NativeModules.AppState; var logError = require('logError'); +var invariant = require('invariant'); -var DEVICE_APPSTATE_EVENT = 'appStateDidChange'; - -var _appStateHandlers = {}; +var _eventHandlers = { + change: new Map(), + memoryWarning: new Map(), +}; /** * `AppStateIOS` can tell you if the app is in the foreground or background, @@ -82,12 +84,23 @@ var AppStateIOS = { type: string, handler: Function ) { - _appStateHandlers[handler] = RCTDeviceEventEmitter.addListener( - DEVICE_APPSTATE_EVENT, - (appStateData) => { - handler(appStateData.app_state); - } + invariant( + ['change', 'memoryWarning'].indexOf(type) !== -1, + 'Trying to subscribe to unknown event: "%s"', type ); + if (type === 'change') { + _eventHandlers[type].set(handler, RCTDeviceEventEmitter.addListener( + 'appStateDidChange', + (appStateData) => { + handler(appStateData.app_state); + } + )); + } else if (type === 'memoryWarning') { + _eventHandlers[type].set(handler, RCTDeviceEventEmitter.addListener( + 'memoryWarning', + handler + )); + } }, /** @@ -97,11 +110,15 @@ var AppStateIOS = { type: string, handler: Function ) { - if (!_appStateHandlers[handler]) { + invariant( + ['change', 'memoryWarning'].indexOf(type) !== -1, + 'Trying to remove listener for unknown event: "%s"', type + ); + if (!_eventHandlers[type].has(handler)) { return; } - _appStateHandlers[handler].remove(); - _appStateHandlers[handler] = null; + _eventHandlers[type].get(handler).remove(); + _eventHandlers[type].delete(handler); }, currentState: (null : ?String), @@ -109,7 +126,7 @@ var AppStateIOS = { }; RCTDeviceEventEmitter.addListener( - DEVICE_APPSTATE_EVENT, + 'appStateDidChange', (appStateData) => { AppStateIOS.currentState = appStateData.app_state; } diff --git a/Libraries/CustomComponents/Navigator/Navigator.js b/Libraries/CustomComponents/Navigator/Navigator.js index b951d7582b5ad5..1ebbc70aa0220e 100644 --- a/Libraries/CustomComponents/Navigator/Navigator.js +++ b/Libraries/CustomComponents/Navigator/Navigator.js @@ -332,7 +332,7 @@ var Navigator = React.createClass({ this._subRouteFocus = []; this.navigatorContext = { // Actions for child navigators or interceptors: - setHandlerForRoute: this.setHandlerForRoute, + setHandlerForIndex: this.setHandlerForIndex, request: this.request, // Contextual utilities @@ -340,14 +340,13 @@ var Navigator = React.createClass({ getCurrentRoutes: this.getCurrentRoutes, // `route` is injected by NavigatorStaticContextContainer - // Contextual nav actions + // Contextual nav action pop: this.requestPop, - popToRoute: this.requestPopTo, - // Legacy, imperitive nav actions. Will transition these to contextual actions jumpBack: this.jumpBack, jumpForward: this.jumpForward, jumpTo: this.jumpTo, + popToRoute: this.popToRoute, push: this.push, replace: this.replace, replaceAtIndex: this.replaceAtIndex, @@ -410,8 +409,6 @@ var Navigator = React.createClass({ switch (action) { case 'pop': return this._handlePop(arg1); - case 'popTo': - return this._handlePopTo(arg1); case 'push': return this._handlePush(arg1); default: @@ -440,30 +437,13 @@ var Navigator = React.createClass({ return true; }, - _handlePopTo: function(destRoute) { - if (destRoute) { - var hasRoute = this.state.routeStack.indexOf(destRoute) !== -1; - if (hasRoute) { - this.popToRoute(destRoute); - return true; - } else { - return false; - } - } - if (this.state.presentedIndex === 0) { - return false; - } - this.pop(); - return true; - }, - _handlePush: function(route) { this.push(route); return true; }, - setHandlerForRoute: function(route, handler) { - this._handlers[this.state.routeStack.indexOf(route)] = handler; + setHandlerForIndex: function(index, handler) { + this._handlers[index] = handler; }, componentDidMount: function() { @@ -1155,17 +1135,13 @@ var Navigator = React.createClass({ this.popToRoute(this.state.routeStack[0]); }, - _getNumToPopForRoute: function(route) { + popToRoute: function(route) { var indexOfRoute = this.state.routeStack.indexOf(route); invariant( indexOfRoute !== -1, - 'Calling pop to route for a route that doesn\'t exist!' + 'Calling popToRoute for a route that doesn\'t exist!' ); - return this.state.presentedIndex - indexOfRoute; - }, - - popToRoute: function(route) { - var numToPop = this._getNumToPopForRoute(route); + var numToPop = this.state.presentedIndex - indexOfRoute; this._popN(numToPop); }, @@ -1262,7 +1238,7 @@ var Navigator = React.createClass({ ...this.navigatorContext, route, setHandler: (handler) => { - this.navigatorContext.setHandlerForRoute(route, handler); + this.navigatorContext.setHandlerForIndex(i, handler); }, onWillFocus: (childRoute) => { this._subRouteFocus[i] = childRoute; diff --git a/Libraries/Network/XMLHttpRequestBase.js b/Libraries/Network/XMLHttpRequestBase.js index 99a327b5f236eb..83e44073e31297 100644 --- a/Libraries/Network/XMLHttpRequestBase.js +++ b/Libraries/Network/XMLHttpRequestBase.js @@ -23,7 +23,7 @@ class XMLHttpRequestBase { readyState: number; responseHeaders: ?Object; responseText: ?string; - status: ?string; + status: number; _method: ?string; _url: ?string; @@ -43,7 +43,7 @@ class XMLHttpRequestBase { this.readyState = this.UNSENT; this.responseHeaders = undefined; this.responseText = undefined; - this.status = undefined; + this.status = 0; this._method = null; this._url = null; @@ -127,7 +127,7 @@ class XMLHttpRequestBase { this._aborted = true; } - callback(status: string, responseHeaders: ?Object, responseText: string): void { + callback(status: number, responseHeaders: ?Object, responseText: string): void { if (this._aborted) { return; } diff --git a/Libraries/ReactIOS/requireNativeComponent.js b/Libraries/ReactIOS/requireNativeComponent.js index c1c3b137662698..a61ae730b8580e 100644 --- a/Libraries/ReactIOS/requireNativeComponent.js +++ b/Libraries/ReactIOS/requireNativeComponent.js @@ -21,6 +21,7 @@ var pointsDiffer = require('pointsDiffer'); var matricesDiffer = require('matricesDiffer'); var sizesDiffer = require('sizesDiffer'); var verifyPropTypes = require('verifyPropTypes'); +var warning = require('warning'); /** * Used to create React components that directly wrap native component @@ -43,6 +44,7 @@ function requireNativeComponent( ): Function { var viewConfig = RCTUIManager[viewName]; if (!viewConfig || !viewConfig.nativeProps) { + warning(false, 'Native component for "%s" does not exist', viewName); return UnimplementedView; } var nativeProps = { diff --git a/Libraries/Sample/Sample.android.js b/Libraries/Sample/Sample.android.js new file mode 100644 index 00000000000000..57cd7240019c5f --- /dev/null +++ b/Libraries/Sample/Sample.android.js @@ -0,0 +1,17 @@ +/** + * Stub of Sample for Android. + * + * @providesModule Sample + * @flow + */ +'use strict'; + +var warning = require('warning'); + +var Sample = { + test: function() { + warning("Not yet implemented for Android."); + } +}; + +module.exports = Sample; diff --git a/Libraries/Sample/Sample.h b/Libraries/Sample/Sample.h new file mode 100644 index 00000000000000..6a13417ad8dbb6 --- /dev/null +++ b/Libraries/Sample/Sample.h @@ -0,0 +1,5 @@ +#import "RCTBridgeModule.h" + +@interface Sample : NSObject + +@end diff --git a/Libraries/Sample/Sample.ios.js b/Libraries/Sample/Sample.ios.js new file mode 100644 index 00000000000000..884e5305c0298c --- /dev/null +++ b/Libraries/Sample/Sample.ios.js @@ -0,0 +1,20 @@ +/** + * @providesModule Sample + * @flow + */ +'use strict'; + +var NativeSample = require('NativeModules').Sample; +var invariant = require('invariant'); + +/** + * High-level docs for the Sample iOS API can be written here. + */ + +var Sample = { + test: function() { + NativeSample.test(); + } +}; + +module.exports = Sample; diff --git a/Libraries/Sample/Sample.m b/Libraries/Sample/Sample.m new file mode 100644 index 00000000000000..d3094111251982 --- /dev/null +++ b/Libraries/Sample/Sample.m @@ -0,0 +1,12 @@ +#import "Sample.h" + +@implementation Sample + +RCT_EXPORT_MODULE() + +RCT_EXPORT_METHOD(test) +{ + // Your implementation here +} + +@end diff --git a/Libraries/Sample/Sample.xcodeproj/project.pbxproj b/Libraries/Sample/Sample.xcodeproj/project.pbxproj new file mode 100644 index 00000000000000..f00a2fd1863b09 --- /dev/null +++ b/Libraries/Sample/Sample.xcodeproj/project.pbxproj @@ -0,0 +1,251 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 13BE3DEE1AC21097009241FE /* Sample.m in Sources */ = {isa = PBXBuildFile; fileRef = 13BE3DED1AC21097009241FE /* Sample.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 58B511D91A9E6C8500147676 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 134814201AA4EA6300B7C361 /* libSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSample.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 13BE3DEC1AC21097009241FE /* Sample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sample.h; sourceTree = ""; }; + 13BE3DED1AC21097009241FE /* Sample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sample.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 58B511D81A9E6C8500147676 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 134814211AA4EA7D00B7C361 /* Products */ = { + isa = PBXGroup; + children = ( + 134814201AA4EA6300B7C361 /* libSample.a */, + ); + name = Products; + sourceTree = ""; + }; + 58B511D21A9E6C8500147676 = { + isa = PBXGroup; + children = ( + 13BE3DEC1AC21097009241FE /* Sample.h */, + 13BE3DED1AC21097009241FE /* Sample.m */, + 134814211AA4EA7D00B7C361 /* Products */, + ); + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 58B511DA1A9E6C8500147676 /* Sample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Sample" */; + buildPhases = ( + 58B511D71A9E6C8500147676 /* Sources */, + 58B511D81A9E6C8500147676 /* Frameworks */, + 58B511D91A9E6C8500147676 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Sample; + productName = RCTDataManager; + productReference = 134814201AA4EA6300B7C361 /* libSample.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 58B511D31A9E6C8500147676 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + ORGANIZATIONNAME = Facebook; + TargetAttributes = { + 58B511DA1A9E6C8500147676 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Sample" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 58B511D21A9E6C8500147676; + productRefGroup = 58B511D21A9E6C8500147676; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 58B511DA1A9E6C8500147676 /* Sample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 58B511D71A9E6C8500147676 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13BE3DEE1AC21097009241FE /* Sample.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 58B511ED1A9E6C8500147676 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 58B511EE1A9E6C8500147676 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 58B511F01A9E6C8500147676 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../React/**", + "$(SRCROOT)/../../node_modules/react-native/React/**", + ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = Sample; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 58B511F11A9E6C8500147676 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../React/**", + ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = Sample; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Sample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58B511ED1A9E6C8500147676 /* Debug */, + 58B511EE1A9E6C8500147676 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Sample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58B511F01A9E6C8500147676 /* Debug */, + 58B511F11A9E6C8500147676 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 58B511D31A9E6C8500147676 /* Project object */; +} diff --git a/Libraries/Sample/package.json b/Libraries/Sample/package.json new file mode 100644 index 00000000000000..3649dfb7c3737d --- /dev/null +++ b/Libraries/Sample/package.json @@ -0,0 +1,5 @@ +{ + "name": "Sample", + "version": "0.0.1", + "keywords": "react-native" +} diff --git a/Libraries/vendor/crypto/crc32.js b/Libraries/vendor/crypto/crc32.js index 1ded3fddfcdddb..540d60aa832b6e 100644 --- a/Libraries/vendor/crypto/crc32.js +++ b/Libraries/vendor/crypto/crc32.js @@ -1,5 +1,5 @@ /** - * @generated SignedSource<<9bce659a43d6f6115b20a18f6c995d8a>> + * @generated SignedSource<<77bdeb858138636c96c405d64b6be55c>> * * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !! This file is a check-in of a static_upstream project! !! @@ -20,57 +20,73 @@ /* jslint bitwise: true */ /** - * Copyright (c) 2006 Andrea Ercolino - * http://www.opensource.org/licenses/mit-license.php + * Modified from the original for performance improvements. + * + * @see http://create.stephan-brumme.com/crc32/ + * @see http://stackoverflow.com/questions/18638900/ + * @copyright 2006 Andrea Ercolino + * @license MIT */ -var table = '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 ' + - '9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 ' + - '90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 ' + - '83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 ' + - '8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD ' + - 'A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ' + - 'ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 ' + - 'B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB ' + - 'B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 ' + - 'E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 ' + - 'E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 ' + - 'F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 ' + - 'FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D ' + - 'D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F ' + - 'DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 ' + - 'CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B ' + - 'C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 ' + - '73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 ' + - '7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 ' + - '6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ' + - '60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD ' + - '48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF ' + - '4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 ' + - '5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B ' + - '5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ' + - '05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 ' + - '0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 ' + - '18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 ' + - '166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D ' + - '3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F ' + - '30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 ' + - '23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B ' + - '2D02EF8D'; + +var table = [ + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, + 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, + 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, + 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, + 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, + 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, + 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, + 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, + 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, + 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, + 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, + 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, + 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, + 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, + 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, + 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, + 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, + 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, + 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, + 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D +]; + +if (global.Int32Array !== undefined) { + table = new Int32Array(table); +} /** * @returns Number */ function crc32(str) { - var crc = 0; - var n = 0; - var x = 0; - crc = crc ^ (-1); - for (var i = 0, iTop = str.length; i < iTop; i++) { - n = (crc ^ str.charCodeAt(i)) & 0xFF; - x = "0x" + table.substr(n * 9, 8); - crc = (crc >>> 8) ^ x; + var crc = -1; + for (var i = 0, len = str.length; i < len; i++) { + crc = (crc >>> 8) ^ table[(crc ^ str.charCodeAt(i)) & 0xFF]; } - return crc ^ (-1); + return ~crc; } module.exports = crc32; diff --git a/React.podspec b/React.podspec index 32f21edad86a83..792308e03823ab 100644 --- a/React.podspec +++ b/React.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "React" - s.version = "0.4.2" + s.version = "0.4.4" s.summary = "Build high quality mobile apps using React." s.description = <<-DESC React Native apps are built using the React JS diff --git a/React/Executors/RCTContextExecutor.m b/React/Executors/RCTContextExecutor.m index ab5efe5a6079ad..89c273481734fd 100644 --- a/React/Executors/RCTContextExecutor.m +++ b/React/Executors/RCTContextExecutor.m @@ -291,21 +291,78 @@ - (void)executeJSCall:(NSString *)name return; } NSError *error; - NSString *argsString = RCTJSONStringify(arguments, &error); + NSString *argsString = (arguments.count == 1) ? RCTJSONStringify(arguments[0], &error) : RCTJSONStringify(arguments, &error); if (!argsString) { RCTLogError(@"Cannot convert argument to string: %@", error); onComplete(nil, error); return; } - NSString *execString = [NSString stringWithFormat:@"require('%@').%@.apply(null, %@);", name, method, argsString]; - JSValueRef jsError = NULL; - JSStringRef execJSString = JSStringCreateWithCFString((__bridge CFStringRef)execString); - JSValueRef result = JSEvaluateScript(strongSelf->_context.ctx, execJSString, NULL, NULL, 0, &jsError); - JSStringRelease(execJSString); + JSValueRef errorJSRef = NULL; + JSValueRef resultJSRef = NULL; + JSGlobalContextRef contextJSRef = JSContextGetGlobalContext(strongSelf->_context.ctx); + JSObjectRef globalObjectJSRef = JSContextGetGlobalObject(strongSelf->_context.ctx); + + // get require + JSStringRef requireNameJSStringRef = JSStringCreateWithUTF8CString("require"); + JSValueRef requireJSRef = JSObjectGetProperty(contextJSRef, globalObjectJSRef, requireNameJSStringRef, &errorJSRef); + JSStringRelease(requireNameJSStringRef); + + if (requireJSRef != NULL && errorJSRef == NULL) { + + // get module + JSStringRef moduleNameJSStringRef = JSStringCreateWithCFString((__bridge CFStringRef)name); + JSValueRef moduleNameJSRef = JSValueMakeString(contextJSRef, moduleNameJSStringRef); + JSValueRef moduleJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)requireJSRef, NULL, 1, (const JSValueRef *)&moduleNameJSRef, &errorJSRef); + JSStringRelease(moduleNameJSStringRef); + + if (moduleJSRef != NULL && errorJSRef == NULL) { + + // get method + JSStringRef methodNameJSStringRef = JSStringCreateWithCFString((__bridge CFStringRef)method); + JSValueRef methodJSRef = JSObjectGetProperty(contextJSRef, (JSObjectRef)moduleJSRef, methodNameJSStringRef, &errorJSRef); + JSStringRelease(methodNameJSStringRef); + + if (methodJSRef != NULL && errorJSRef == NULL) { + + // direct method invoke with no arguments + if (arguments.count == 0) { + resultJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)methodJSRef, (JSObjectRef)moduleJSRef, 0, NULL, &errorJSRef); + } + // direct method invoke with 1 argument + else if(arguments.count == 1) { + JSStringRef argsJSStringRef = JSStringCreateWithCFString((__bridge CFStringRef)argsString); + JSValueRef argsJSRef = JSValueMakeFromJSONString(contextJSRef, argsJSStringRef); + resultJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)methodJSRef, (JSObjectRef)moduleJSRef, 1, &argsJSRef, &errorJSRef); + JSStringRelease(argsJSStringRef); + } else { + // apply invoke with array of arguments + + // get apply + JSStringRef applyNameJSStringRef = JSStringCreateWithUTF8CString("apply"); + JSValueRef applyJSRef = JSObjectGetProperty(contextJSRef, (JSObjectRef)methodJSRef, applyNameJSStringRef, &errorJSRef); + JSStringRelease(applyNameJSStringRef); + + if (applyJSRef != NULL && errorJSRef == NULL) { + // invoke apply + JSStringRef argsJSStringRef = JSStringCreateWithCFString((__bridge CFStringRef)argsString); + JSValueRef argsJSRef = JSValueMakeFromJSONString(contextJSRef, argsJSStringRef); + + JSValueRef args[2]; + args[0] = JSValueMakeNull(contextJSRef); + args[1] = argsJSRef; + + resultJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)applyJSRef, (JSObjectRef)methodJSRef, 2, args, &errorJSRef); + JSStringRelease(argsJSStringRef); + } + } + } + } + + } - if (!result) { - onComplete(nil, RCTNSErrorFromJSError(strongSelf->_context.ctx, jsError)); + if (!resultJSRef) { + onComplete(nil, RCTNSErrorFromJSError(contextJSRef, errorJSRef)); return; } @@ -315,8 +372,8 @@ - (void)executeJSCall:(NSString *)name id objcValue; // We often return `null` from JS when there is nothing for native side. JSONKit takes an extra hundred microseconds // to handle this simple case, so we are adding a shortcut to make executeJSCall method even faster - if (!JSValueIsNull(strongSelf->_context.ctx, result)) { - JSStringRef jsJSONString = JSValueCreateJSONString(strongSelf->_context.ctx, result, 0, nil); + if (!JSValueIsNull(contextJSRef, resultJSRef)) { + JSStringRef jsJSONString = JSValueCreateJSONString(contextJSRef, resultJSRef, 0, nil); if (jsJSONString) { NSString *objcJSONString = (__bridge_transfer NSString *)JSStringCopyCFString(kCFAllocatorDefault, jsJSONString); JSStringRelease(jsJSONString); diff --git a/React/Modules/RCTAppState.m b/React/Modules/RCTAppState.m index 9743e504209704..8c46655c662041 100644 --- a/React/Modules/RCTAppState.m +++ b/React/Modules/RCTAppState.m @@ -53,11 +53,21 @@ - (instancetype)init selector:@selector(handleAppStateDidChange) name:name object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleMemoryWarning) + name:UIApplicationDidReceiveMemoryWarningNotification + object:nil]; } } return self; } +- (void)handleMemoryWarning +{ + [_bridge.eventDispatcher sendDeviceEventWithName:@"memoryWarning" + body:nil]; +} - (void)dealloc { diff --git a/docs/LinkingLibraries.md b/docs/LinkingLibraries.md index 560ed6b590c757..309a1a47139ebc 100644 --- a/docs/LinkingLibraries.md +++ b/docs/LinkingLibraries.md @@ -17,7 +17,7 @@ For most of the libs it will be as simple as dragging two files, sometimes a thi step will be necessary, but no more than that. _All the libraries we ship with React Native live on the `Libraries` folder in -the root of the repository. Some of them are pure JavaScript, and you just need +the root of the repository. Some of them are pure JavaScript, and you only need to `require` it. Other libraries also rely on some native code, in that case you'll have to add these files to your app, otherwise the app will throw an error as soon as you try to use the library._ @@ -47,9 +47,8 @@ Not every library will need this step, what you need to consider is: _Do I need to know the contents of the library at compile time?_ -What that means is, are you using this library on the native site or just in -JavaScript? If you are just using it in JavaScript, you are good to go! - +What that means is, are you using this library on the native side or only in +JavaScript? If you are only using it in JavaScript, you are good to go! This step is not necessary for libraries that we ship with React Native with the exception of `PushNotificationIOS` and `LinkingIOS`. diff --git a/docs/NativeComponentsIOS.md b/docs/NativeComponentsIOS.md index e15a6ef7e8fc05..acdaaa62deebf5 100644 --- a/docs/NativeComponentsIOS.md +++ b/docs/NativeComponentsIOS.md @@ -87,8 +87,6 @@ class MapView extends React.Component { } } -var RCTMap = requireNativeComponent('RCTMap', MapView); - MapView.propTypes = { /** * When this property is set to `true` and a valid camera is associated @@ -100,6 +98,8 @@ MapView.propTypes = { pitchEnabled: React.PropTypes.bool, }; +var RCTMap = requireNativeComponent('RCTMap', MapView); + module.exports = MapView; ``` diff --git a/init.sh b/init.sh deleted file mode 100755 index e7703f2965f2a5..00000000000000 --- a/init.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env ruby - -def cp(src, dest, app_name) - if File.directory?(src) - Dir.mkdir(dest) unless Dir.exists?(dest) - else - content = File.read(src) - .gsub("SampleApp", app_name) - .gsub("Examples/#{app_name}/", "") - .gsub("../../Libraries/", "node_modules/react-native/Libraries/") - .gsub("../../React/", "node_modules/react-native/React/") - File.write(dest, content) - end -end - -def main(dest, app_name) - source = File.expand_path("../Examples/SampleApp", __FILE__) - files = Dir.chdir(source) { Dir["**/*"] } - .reject { |file| file["project.xcworkspace"] || file["xcuserdata"] } - .each { |file| - new_file = file - .gsub("SampleApp", app_name) - .gsub(/^_/, ".") - cp File.join(source, file), File.join(dest, new_file), app_name - } -end - -if ARGV.count == 0 - puts "Usage: #{__FILE__} " - puts "" - puts "This script will bootstrap new React Native app in current folder" -else - app_name = ARGV.first - dest = Dir.pwd - puts "Setting up new React Native app in #{dest}" - puts "" - - main(dest, app_name) - - puts "Next steps:" - puts "" - puts " Open #{File.join(dest, app_name)}.xcodeproj in Xcode" - puts " Hit Run button" - puts "" -end - diff --git a/lint/linterTransform.js b/lint/linterTransform.js deleted file mode 100644 index 669baf556c442c..00000000000000 --- a/lint/linterTransform.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * 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. - */ -'use strict'; - -var eslint = require('eslint'); - -var ignoredStylisticRules = { - 'key-spacing': false, - 'comma-spacing': true, - 'no-multi-spaces': true, - 'brace-style': true, - 'camelcase': true, - 'consistent-this': true, - 'eol-last': true, - 'func-names': true, - 'func-style': true, - 'new-cap': true, - 'new-parens': true, - 'no-nested-ternary': true, - 'no-array-constructor': true, - 'no-lonely-if': true, - 'no-new-object': true, - 'no-spaced-func': true, - 'no-space-before-semi': true, - 'no-ternary': true, - 'no-trailing-spaces': true, - 'no-underscore-dangle': true, - 'no-wrap-func': true, - 'no-mixed-spaces-and-tabs': true, - 'quotes': true, - 'quote-props': true, - 'semi': true, - 'sort-vars': true, - 'space-after-keywords': true, - 'space-in-brackets': true, - 'space-in-parens': true, - 'space-infix-ops': true, - 'space-return-throw-case': true, - 'space-unary-word-ops': true, - 'max-nested-callbacks': true, - 'one-var': true, - 'wrap-regex': true, - 'curly': true, - 'no-mixed-requires': true, -}; - -function setLinterTransform(transformSource) { - var originalVerify = eslint.linter.verify; - eslint.linter.verify = function(text, config, filename, saveState) { - var transformedText; - try { - transformedText = transformSource(text, filename); - } catch (e) { - return [{ - severity: 2, - line: e.lineNumber, - message: e.message, - source: text - }]; - } - var originalLines = text.split('\n'); - var transformedLines = transformedText.split('\n'); - var warnings = originalVerify.call(eslint.linter, transformedText, config, filename, saveState); - - // JSX and ES6 transforms usually generate pretty ugly code. Let's skip lint warnings - // about code style for lines that have been changed by transform step. - // Note that more important issues, like use of undefined vars, will still be reported. - return warnings.filter(function(error) { - var lineHasBeenTransformed = originalLines[error.line - 1] !== transformedLines[error.line - 1]; - var shouldIgnore = ignoredStylisticRules[error.ruleId] && lineHasBeenTransformed; - return !shouldIgnore; - }); - }; -} - -module.exports = { - setLinterTransform: setLinterTransform, -}; diff --git a/linter.js b/linter.js deleted file mode 100644 index f243a2d2fb8ce3..00000000000000 --- a/linter.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * 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. - */ -'use strict'; - -var transformSource = require('./jestSupport/scriptPreprocess.js').transformSource; -var linterTransform = require('./lint/linterTransform'); - -linterTransform.setLinterTransform(transformSource); - -// Run the original CLI -require('eslint/bin/eslint'); diff --git a/local-cli/cli.js b/local-cli/cli.js index 99d05c7c9fc647..4f75e83db36d44 100644 --- a/local-cli/cli.js +++ b/local-cli/cli.js @@ -6,8 +6,11 @@ var spawn = require('child_process').spawn; var path = require('path'); + +var init = require('./init.js'); var install = require('./install.js'); var bundle = require('./bundle.js'); +var newLibrary = require('./new-library.js'); function printUsage() { console.log([ @@ -16,7 +19,16 @@ function printUsage() { 'Commands:', ' start: starts the webserver', ' install: installs npm react components', - ' bundle: builds the javascript bundle for offline use' + ' bundle: builds the javascript bundle for offline use', + ' new-library: generates a native library bridge' + ].join('\n')); + process.exit(1); +} + +function printInitWarning() { + console.log([ + 'Looks like React Native project already exists in the current', + 'folder. Run this command from a different folder or remove node_modules/react-native' ].join('\n')); process.exit(1); } @@ -41,6 +53,12 @@ function run() { case 'bundle': bundle.init(args); break; + case 'new-library': + newLibrary.init(args); + break; + case 'init': + printInitWarning(); + break; default: console.error('Command `%s` unrecognized', args[0]); printUsage(); @@ -48,10 +66,6 @@ function run() { // Here goes any cli commands we need to } -function init(root, projectName) { - spawn(path.resolve(__dirname, '../init.sh'), [projectName], {stdio:'inherit'}); -} - if (require.main === module) { run(); } diff --git a/local-cli/generator-utils.js b/local-cli/generator-utils.js new file mode 100644 index 00000000000000..449e000ae021d5 --- /dev/null +++ b/local-cli/generator-utils.js @@ -0,0 +1,47 @@ +'use strict'; + +var path = require('path'); +var fs = require('fs'); + +function copyAndReplace(src, dest, replacements) { + if (fs.lstatSync(src).isDirectory()) { + if (!fs.existsSync(dest)) { + fs.mkdirSync(dest); + } + } else { + var content = fs.readFileSync(src, 'utf8'); + Object.keys(replacements).forEach(function(regex) { + content = content.replace(new RegExp(regex, 'g'), replacements[regex]); + }); + fs.writeFileSync(dest, content); + } +} + +function walk(current) { + if (!fs.lstatSync(current).isDirectory()) { + return [current]; + } + + var files = fs.readdirSync(current).map(function(child) { + child = path.join(current, child); + return walk(child); + }); + return [].concat.apply([current], files); +} + +function validatePackageName(name) { + if (!name.match(/^[$A-Z_][0-9A-Z_$]*$/i)) { + console.error( + '"%s" is not a valid name for a project. Please use a valid identifier ' + + 'name (alphanumeric).', + name + ); + process.exit(1); + } +} + +module.exports = { + copyAndReplace: copyAndReplace, + walk: walk, + validatePackageName: validatePackageName +}; diff --git a/local-cli/init.js b/local-cli/init.js new file mode 100755 index 00000000000000..6441edd705a2e7 --- /dev/null +++ b/local-cli/init.js @@ -0,0 +1,37 @@ +'use strict'; + +var path = require('path'); +var utils = require('./generator-utils'); + +function init(projectDir, appName) { + console.log('Setting up new React Native app in ' + projectDir); + var source = path.resolve(__dirname, '..', 'Examples/SampleApp'); + + utils.walk(source).forEach(function(f) { + f = f.replace(source + '/', ''); // Strip off absolute path + if (f === 'project.xcworkspace' || f.indexOf('.xcodeproj/xcuserdata') !== -1) { + return; + } + + var replacements = { + 'Examples/SampleApp/': '', + '../../Libraries/': 'node_modules/react-native/Libraries/', + '../../React/': 'node_modules/react-native/React/', + 'SampleApp': appName + }; + + var dest = f.replace(/SampleApp/g, appName).replace(/^_/, '.'); + utils.copyAndReplace( + path.resolve(source, f), + path.resolve(projectDir, dest), + replacements + ); + }); + + console.log('Next Steps:'); + console.log(' Open ' + path.resolve(projectDir, appName) + '.xcodeproj in Xcode'); + console.log(' Hit Run button'); + console.log(''); +} + +module.exports = init; diff --git a/local-cli/new-library.js b/local-cli/new-library.js new file mode 100644 index 00000000000000..533594aca592ec --- /dev/null +++ b/local-cli/new-library.js @@ -0,0 +1,61 @@ +'use strict'; + +var path = require('path'); +var fs = require('fs'); +var utils = require('./generator-utils'); + +function showHelp() { + console.log([ + 'Usage: react-native new-library ', + '' + ].join('\n')); + process.exit(1); +} + +function newLibrary(libraryName) { + var root = process.cwd(); + var libraries = path.resolve(root, 'Libraries'); + var libraryDest = path.resolve(libraries, libraryName); + var source = path.resolve('node_modules', 'react-native', 'Libraries', 'Sample') + '/'; + + if (!fs.existsSync(libraries)) { + fs.mkdir(libraries); + } + + if (fs.existsSync(libraryDest)) { + console.log('Library already exists in', libraryDest); + process.exit(1); + } + + utils.walk(source).forEach(function(f) { + f = f.replace(source, ''); // Strip off absolute path + if (f === 'project.xcworkspace' || f.indexOf('.xcodeproj/xcuserdata') !== -1) { + return; + } + + var dest = f.replace(/Sample/g, libraryName).replace(/^_/, '.'); + utils.copyAndReplace( + path.resolve(source, f), + path.resolve(libraryDest, dest), + { 'Sample': libraryName } + ); + }); + + console.log('Created library in', libraryDest); + console.log('Next Steps:'); + console.log(' Link your library in Xcode:'); + console.log(' https://facebook.github.io/react-native/docs/linking-libraries.html#content'); + console.log(''); +} + +module.exports = { + init: function(args) { + var libraryName = args[1]; + if (!libraryName) { + showHelp(); + } + utils.validatePackageName(libraryName); + + newLibrary(libraryName); + } +}; diff --git a/package.json b/package.json index a2c7a38b408da4..a4dd3946979468 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,8 @@ }, "devDependencies": { "jest-cli": "0.4.5", - "eslint": "0.9.2" + "babel-eslint": "3.1.5", + "eslint": "0.21.2", + "eslint-plugin-react": "2.3.0" } } diff --git a/packager/react-packager/index.js b/packager/react-packager/index.js index a7b6264b7b740f..6be111997cca48 100644 --- a/packager/react-packager/index.js +++ b/packager/react-packager/index.js @@ -18,14 +18,17 @@ exports.middleware = function(options) { return server.processRequest.bind(server); }; -exports.buildPackageFromUrl = function(options, reqUrl) { - Activity.disable(); - // Don't start the filewatcher or the cache. - if (options.nonPersistent == null) { - options.nonPersistent = true; - } +exports.buildPackage = function(options, packageOptions) { + var server = createServer(options); + return server.buildPackage(packageOptions) + .then(function(p) { + server.end(); + return p; + }); +}; - var server = new Server(options); +exports.buildPackageFromUrl = function(options, reqUrl) { + var server = createServer(options); return server.buildPackageFromUrl(reqUrl) .then(function(p) { server.end(); @@ -34,13 +37,7 @@ exports.buildPackageFromUrl = function(options, reqUrl) { }; exports.getDependencies = function(options, main) { - Activity.disable(); - // Don't start the filewatcher or the cache. - if (options.nonPersistent == null) { - options.nonPersistent = true; - } - - var server = new Server(options); + var server = createServer(options); return server.getDependencies(main) .then(function(r) { server.end(); @@ -60,3 +57,13 @@ function useGracefulFs() { } }); } + +function createServer(options) { + Activity.disable(); + // Don't start the filewatcher or the cache. + if (options.nonPersistent == null) { + options.nonPersistent = true; + } + + return new Server(options); +} diff --git a/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js b/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js index 5948916a7353d8..22ca53e632d4ab 100644 --- a/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js +++ b/packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js @@ -57,25 +57,34 @@ describe('Transformer', function() { }); pit('should add file info to parse errors', function() { + var message = 'message'; + var snippet = 'snippet'; + require('fs').readFile.mockImpl(function(file, callback) { callback(null, 'var x;\nvar answer = 1 = x;'); }); workers.mockImpl(function(data, callback) { - var esprimaError = new Error('Error: Line 2: Invalid left-hand side in assignment'); - esprimaError.description = 'Invalid left-hand side in assignment'; - esprimaError.lineNumber = 2; - esprimaError.column = 15; - callback(null, {error: esprimaError}); + var babelError = new SyntaxError(message); + babelError.type = 'SyntaxError'; + babelError.description = message; + babelError.loc = { + line: 2, + column: 15, + }; + babelError.codeFrame = snippet; + callback(babelError); }); return new Transformer(OPTIONS).loadFileAndTransform('foo-file.js') .catch(function(error) { expect(error.type).toEqual('TransformError'); - expect(error.snippet).toEqual([ - 'var answer = 1 = x;', - ' ^', - ].join('\n')); + expect(error.message).toBe('SyntaxError ' + message); + expect(error.lineNumber).toBe(2); + expect(error.column).toBe(15); + expect(error.filename).toBe('foo-file.js'); + expect(error.description).toBe(message); + expect(error.snippet).toBe(snippet); }); }); }); diff --git a/packager/react-packager/src/JSTransformer/index.js b/packager/react-packager/src/JSTransformer/index.js index 2dc5e20bd48071..513d4394e17f4e 100644 --- a/packager/react-packager/src/JSTransformer/index.js +++ b/packager/react-packager/src/JSTransformer/index.js @@ -99,7 +99,12 @@ Transformer.prototype.loadFileAndTransform = function(filePath) { }).then( function(res) { if (res.error) { - throw formatError(res.error, filePath, sourceCode); + console.warn( + 'Error property on the result value form the transformer', + 'module is deprecated and will be removed in future versions.', + 'Please pass an error object as the first argument to the callback' + ); + throw formatError(res.error, filePath); } return new ModuleTransport({ @@ -110,6 +115,8 @@ Transformer.prototype.loadFileAndTransform = function(filePath) { }); } ); + }).catch(function(err) { + throw formatError(err, filePath); }); }); }; @@ -118,8 +125,8 @@ function TransformError() {} util.inherits(TransformError, SyntaxError); function formatError(err, filename, source) { - if (err.lineNumber && err.column) { - return formatEsprimaError(err, filename, source); + if (err.loc) { + return formatBabelError(err, filename, source); } else { return formatGenericError(err, filename, source); } @@ -136,26 +143,16 @@ function formatGenericError(err, filename) { return error; } -function formatEsprimaError(err, filename, source) { - var stack = err.stack.split('\n'); - stack.shift(); - - var msg = 'TransformError: ' + err.description + ' ' + filename + ':' + - err.lineNumber + ':' + err.column; - var sourceLine = source.split('\n')[err.lineNumber - 1]; - var snippet = sourceLine + '\n' + new Array(err.column - 1).join(' ') + '^'; - - stack.unshift(msg); - +function formatBabelError(err, filename) { var error = new TransformError(); - error.message = msg; error.type = 'TransformError'; - error.stack = stack.join('\n'); - error.snippet = snippet; + error.message = (err.type || error.type) + ' ' + err.message; + error.stack = err.stack; + error.snippet = err.codeFrame; + error.lineNumber = err.loc.line; + error.column = err.loc.column; error.filename = filename; - error.lineNumber = err.lineNumber; - error.column = err.column; - error.description = err.description; + error.description = err.message; return error; } diff --git a/packager/react-packager/src/Packager/Package.js b/packager/react-packager/src/Packager/Package.js index 70f57c4ab23c6f..6b53894614932f 100644 --- a/packager/react-packager/src/Packager/Package.js +++ b/packager/react-packager/src/Packager/Package.js @@ -15,6 +15,8 @@ var ModuleTransport = require('../lib/ModuleTransport'); module.exports = Package; +var SOURCEMAPPING_URL = '\n\/\/@ sourceMappingURL='; + function Package(sourceMapUrl) { this._finalized = false; this._modules = []; @@ -96,12 +98,11 @@ Package.prototype.getSource = function(options) { } var source = this._getSource(); - source += '\n\/\/@ sourceMappingURL='; if (options.inlineSourceMap) { - source += this._getInlineSourceMap(); - } else { - source += this._sourceMapUrl; + source += SOURCEMAPPING_URL + this._getInlineSourceMap(); + } else if (this._sourceMapUrl) { + source += SOURCEMAPPING_URL + this._sourceMapUrl; } return source; diff --git a/packager/react-packager/src/Packager/__tests__/Package-test.js b/packager/react-packager/src/Packager/__tests__/Package-test.js index 1d8c3dd12c1d03..d43c65c0f8c06f 100644 --- a/packager/react-packager/src/Packager/__tests__/Package-test.js +++ b/packager/react-packager/src/Packager/__tests__/Package-test.js @@ -47,6 +47,26 @@ describe('Package', function() { ].join('\n')); }); + it('should be ok to leave out the source map url', function() { + var p = new Package(); + p.addModule(new ModuleTransport({ + code: 'transformed foo;', + sourceCode: 'source foo', + sourcePath: 'foo path', + })); + p.addModule(new ModuleTransport({ + code: 'transformed bar;', + sourceCode: 'source bar', + sourcePath: 'bar path', + })); + + p.finalize({}); + expect(p.getSource()).toBe([ + 'transformed foo;', + 'transformed bar;', + ].join('\n')); + }); + it('should create a package and add run module code', function() { ppackage.addModule(new ModuleTransport({ code: 'transformed foo;', diff --git a/packager/react-packager/src/Server/__tests__/Server-test.js b/packager/react-packager/src/Server/__tests__/Server-test.js index 58a1aca798cb6f..e4e7b5088767a0 100644 --- a/packager/react-packager/src/Server/__tests__/Server-test.js +++ b/packager/react-packager/src/Server/__tests__/Server-test.js @@ -230,7 +230,7 @@ describe('processRequest', function() { }); }); - describe.only('/assets endpoint', function() { + describe('/assets endpoint', function() { var AssetServer; beforeEach(function() { AssetServer = require('../../AssetServer'); @@ -257,4 +257,30 @@ describe('processRequest', function() { }); }); + + describe('buildPackage(options)', function() { + it('Calls the packager with the correct args', function() { + server.buildPackage({ + entryFile: 'foo file' + }); + expect(Packager.prototype.package).toBeCalledWith( + 'foo file', + true, + undefined, + true + ); + }); + }); + + describe('buildPackageFromUrl(options)', function() { + it('Calls the packager with the correct args', function() { + server.buildPackageFromUrl('/path/to/foo.bundle?dev=false&runModule=false'); + expect(Packager.prototype.package).toBeCalledWith( + 'path/to/foo.js', + false, + '/path/to/foo.map', + false + ); + }); + }); }); diff --git a/packager/react-packager/src/Server/index.js b/packager/react-packager/src/Server/index.js index d4da5ae106f4ce..0ce5c584715bd3 100644 --- a/packager/react-packager/src/Server/index.js +++ b/packager/react-packager/src/Server/index.js @@ -129,7 +129,7 @@ Server.prototype._onFileChange = function(type, filepath, root) { }; Server.prototype._rebuildPackages = function() { - var buildPackage = this._buildPackage.bind(this); + var buildPackage = this.buildPackage.bind(this); var packages = this._packages; Object.keys(packages).forEach(function(key) { var options = getOptionsFromUrl(key); @@ -171,18 +171,47 @@ Server.prototype.end = function() { ]); }; -Server.prototype._buildPackage = function(options) { +var packageOpts = declareOpts({ + sourceMapUrl: { + type: 'string', + required: false, + }, + entryFile: { + type: 'string', + required: true, + }, + dev: { + type: 'boolean', + default: true, + }, + minify: { + type: 'boolean', + default: false, + }, + runModule: { + type: 'boolean', + default: true, + }, + inlineSourceMap: { + type: 'boolean', + default: false, + }, +}); + +Server.prototype.buildPackage = function(options) { + var opts = packageOpts(options); + return this._packager.package( - options.main, - options.runModule, - options.sourceMapUrl, - options.dev + opts.entryFile, + opts.runModule, + opts.sourceMapUrl, + opts.dev ); }; Server.prototype.buildPackageFromUrl = function(reqUrl) { var options = getOptionsFromUrl(reqUrl); - return this._buildPackage(options); + return this.buildPackage(options); }; Server.prototype.getDependencies = function(main) { @@ -321,7 +350,7 @@ Server.prototype.processRequest = function(req, res, next) { var startReqEventId = Activity.startEvent('request:' + req.url); var options = getOptionsFromUrl(req.url); - var building = this._packages[req.url] || this._buildPackage(options); + var building = this._packages[req.url] || this.buildPackage(options); this._packages[req.url] = building; building.then( @@ -363,7 +392,7 @@ function getOptionsFromUrl(reqUrl) { return { sourceMapUrl: pathname.replace(/\.bundle$/, '.map'), - main: entryFile, + entryFile: entryFile, dev: getBoolOptionFromQuery(urlObj.query, 'dev', true), minify: getBoolOptionFromQuery(urlObj.query, 'minify'), runModule: getBoolOptionFromQuery(urlObj.query, 'runModule', true), diff --git a/packager/transformer.js b/packager/transformer.js index 00beeaddeeda11..a2efcea3bb2b54 100644 --- a/packager/transformer.js +++ b/packager/transformer.js @@ -10,40 +10,37 @@ */ 'use strict'; -var jstransform = require('jstransform').transform; +var babel = require('babel'); -var reactVisitors = - require('react-tools/vendor/fbtransform/visitors').getAllVisitors(); -var staticTypeSyntax = - require('jstransform/visitors/type-syntax').visitorList; -var trailingCommaVisitors = - require('jstransform/visitors/es7-trailing-comma-visitors.js').visitorList; - -// Note that reactVisitors now handles ES6 classes, rest parameters, arrow -// functions, template strings, and object short notation. -var visitorList = reactVisitors.concat(trailingCommaVisitors); - -function transform(srcTxt, filename) { - var options = { - es3: true, - sourceType: 'nonStrictModule', +function transform(srcTxt, filename, options) { + var result = babel.transform(srcTxt, { + retainLines: true, + compact: true, + comments: false, filename: filename, + whitelist: [ + 'es6.arrowFunctions', + 'es6.blockScoping', + 'es6.classes', + 'es6.destructuring', + 'es6.parameters.rest', + 'es6.properties.computed', + 'es6.properties.shorthand', + 'es6.spread', + 'es6.templateLiterals', + 'es7.trailingFunctionCommas', + 'es7.objectRestSpread', + 'flow', + 'react', + ], + sourceFileName: filename, + sourceMaps: false, + extra: options || {}, + }); + + return { + code: result.code, }; - - // These tranforms mostly just erase type annotations and static typing - // related statements, but they were conflicting with other tranforms. - // Running them first solves that problem - var staticTypeSyntaxResult = jstransform( - staticTypeSyntax, - srcTxt, - options - ); - - return jstransform( - visitorList, - staticTypeSyntaxResult.code, - options - ); } module.exports = function(data, callback) { @@ -54,15 +51,8 @@ module.exports = function(data, callback) { data.filename ); } catch (e) { - return callback(null, { - error: { - lineNumber: e.lineNumber, - column: e.column, - message: e.message, - stack: e.stack, - description: e.description - } - }); + callback(e); + return; } callback(null, result); diff --git a/react-native-cli/index.js b/react-native-cli/index.js index 7bd237e021df44..871a78b987ffd7 100755 --- a/react-native-cli/index.js +++ b/react-native-cli/index.js @@ -7,6 +7,7 @@ var fs = require('fs'); var path = require('path'); var spawn = require('child_process').spawn; +var prompt = require("prompt"); var CLI_MODULE_PATH = function() { return path.resolve( @@ -55,7 +56,7 @@ if (cli) { } } -function init(name) { +function validatePackageName(name) { if (!name.match(/^[$A-Z_][0-9A-Z_$]*$/i)) { console.error( '"%s" is not a valid name for a project. Please use a valid identifier ' + @@ -64,7 +65,40 @@ function init(name) { ); process.exit(1); } +} + +function init(name) { + validatePackageName(name); + + if (fs.existsSync(name)) { + createAfterConfirmation(name) + } else { + createProject(name); + } +} + +function createAfterConfirmation(name) { + prompt.start(); + + var property = { + name: 'yesno', + message: 'Directory ' + name + ' already exist. Continue?', + validator: /y[es]*|n[o]?/, + warning: 'Must respond yes or no', + default: 'no' + }; + + prompt.get(property, function (err, result) { + if (result.yesno[0] === 'y') { + createProject(name); + } else { + console.log('Project initialization canceled'); + process.exit(); + } + }); +} +function createProject(name) { var root = path.resolve(name); var projectName = path.basename(root); diff --git a/react-native-cli/package.json b/react-native-cli/package.json index 8644e7eae217ca..90450c3ea6ca71 100644 --- a/react-native-cli/package.json +++ b/react-native-cli/package.json @@ -5,5 +5,8 @@ "main": "index.js", "bin": { "react-native": "index.js" + }, + "dependencies": { + "prompt": "^0.2.14" } } diff --git a/website/jsdocs/jsdocs.js b/website/jsdocs/jsdocs.js index 086ad296683e66..f81f0e7c01ece6 100644 --- a/website/jsdocs/jsdocs.js +++ b/website/jsdocs/jsdocs.js @@ -209,13 +209,21 @@ function sanitizeTypehint(string) { /** * @param {object} node + * @param {object} docNode Node used for location/docblock purposes * @param {object} state * @param {string} source * @param {array} commentsForFile * @param {array} linesForFile * @return {object} */ -function getFunctionData(node, state, source, commentsForFile, linesForFile) { +function getFunctionData( + node, + docNode, + state, + source, + commentsForFile, + linesForFile +) { var params = []; var typechecks = commentsForFile.typechecks; var typehintsFromBlock = null; @@ -287,9 +295,9 @@ function getFunctionData(node, state, source, commentsForFile, linesForFile) { }); } return { - line: node.loc.start.line, + line: docNode.loc.start.line, source: source.substring.apply(source, node.range), - docblock: getDocBlock(node, commentsForFile, linesForFile), + docblock: getDocBlock(docNode, commentsForFile, linesForFile), modifiers: [], params: params, tparams: tparams, @@ -320,7 +328,7 @@ function getObjectData(node, state, source, scopeChain, switch (property.value.type) { case Syntax.FunctionExpression: - var methodData = getFunctionData(property.value, state, source, + var methodData = getFunctionData(property.value, property, state, source, commentsForFile, linesForFile); methodData.name = property.key.name || property.key.value; methodData.source = source.substring.apply(source, property.range); @@ -335,7 +343,8 @@ function getObjectData(node, state, source, scopeChain, if (expr) { if (expr.type === Syntax.FunctionDeclaration) { var functionData = - getFunctionData(expr, state, source, commentsForFile, linesForFile); + getFunctionData(expr, property, state, source, commentsForFile, + linesForFile); functionData.name = property.key.name || property.key.value; functionData.modifiers.push('static'); methods.push(functionData); @@ -389,7 +398,7 @@ function getClassData(node, state, source, commentsForFile, linesForFile) { if (bodyItem.type === Syntax.MethodDefinition) { if (bodyItem.value.type === Syntax.FunctionExpression) { var methodData = - getFunctionData(bodyItem.value, state, source, + getFunctionData(bodyItem.value, bodyItem, state, source, commentsForFile, linesForFile); methodData.name = bodyItem.key.name; methodData.source = source.substring.apply(source, bodyItem.range); @@ -529,7 +538,8 @@ function parseSource(source) { break; case Syntax.FunctionDeclaration: case Syntax.FunctionExpression: - data = getFunctionData(definition, _state, source, ast.comments, lines); + data = getFunctionData(definition, definition, _state, source, + ast.comments, lines); data.type = 'function'; break; default: diff --git a/website/server/extractDocs.js b/website/server/extractDocs.js index a4500e9ebb798c..66129bb290fb9c 100644 --- a/website/server/extractDocs.js +++ b/website/server/extractDocs.js @@ -157,6 +157,7 @@ var components = [ '../Libraries/Components/Navigation/NavigatorIOS.ios.js', '../Libraries/Picker/PickerIOS.ios.js', '../Libraries/Components/ScrollView/ScrollView.js', + '../Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js', '../Libraries/Components/SliderIOS/SliderIOS.js', '../Libraries/Components/SwitchIOS/SwitchIOS.ios.js', '../Libraries/Components/TabBarIOS/TabBarIOS.ios.js',