prepack/scripts
Dominic Gannaway 810056d1ec Add React functional component folding
Summary:
Release note: Adds experimental React functional component folding optimizations

This PR is stacked upon PRs #1118 and #1117. Thus, those PRs should be merged before this PR is merged to reduce noise in the diff.

This PR adds a new React Reconciler into Prepack's serialization process, so that React components trees can be folded/inlined into a single component at build time. To fold a component tree, it must be explicitly done via `__registerReactComponentRoot(nameOfComponent)`.

This PR only attempts to fold React functional components, not React ES2015 class components (that will come in another PR at a later date). Furthermore, the `props` parameter on a root component must contain Flow type annotations (otherwise we will have no idea what the values might be). Support flow `propTypes` might also be an addition, but not for this PR.

If the reconciler comes across a component that it cannot fold/inline, it will "bail-out" and try and continue the process without that particular component being folded into the tree.

An example of how this all works (input):

```jsx
function App(props: {title: string}) {
  return (
    <div>
      <ChildComponent title={props.title} />
    </div>
  );
}

function ChildComponent(props) {
  return (
    <span>
      <SubChildComponent {...props} />
    </span>
  );
}

function SubChildComponent(props) {
  return <span>{props.title.toString()}</span>
}

__registerReactComponentRoot(App);

global.App = App;
```

Output:
```jsx
(function () {
  "use strict";

  var _$1 = this;

  var _0 = function (props) {
    var _$0 = props.title;
    return <div><span><span>{_$0}</span></span></div>;
  };

  _$1.App = _0;
}).call(this);
```
Closes https://github.com/facebook/prepack/pull/1120

Differential Revision: D6237333

Pulled By: trueadm

fbshipit-source-id: b58c7d8979ca79a766bb2ee2eb01a380d37c3101
2017-11-06 05:07:36 -08:00
..
detect_bad_deps.js Add React functional component folding 2017-11-06 05:07:36 -08:00
generate-sourcemaps-test.js Allow Prepack CLI to prepack multiple source files 2017-08-14 22:41:24 -07:00
instrumentor.js Always use fast traversal function when trivially possible. 2017-07-24 16:39:31 -07:00
multi-runner.js Fix prettier and lint failures 2017-10-23 00:00:47 -07:00
prettier.js Making Prettier a check-in gate 2017-07-07 11:35:32 -07:00
test262-runner.js Fix prettier and lint failures 2017-10-23 00:00:47 -07:00
test-error-handler.js Allow required modules to throw conditionally 2017-10-30 13:00:01 -07:00
test-internal.js Serialize independent functions 2017-09-25 16:53:45 -07:00
test-node-cli-mode.sh Add minimal test case for the node-cli mode 2017-05-18 15:08:39 -07:00
test-react.js Add React functional component folding 2017-11-06 05:07:36 -08:00
test-residual.js Throw FatalError after reporting generic introspection error 2017-07-14 14:58:00 -07:00
test-runner.js Support running tests in inferior JavaScript repl. 2017-10-30 17:29:46 -07:00
test-sourcemaps.sh Extract scripts from npm package (#463) 2017-04-26 12:26:18 -07:00
test-std-in.sh Fixing output to look less like a failure on success 2017-07-13 16:53:40 -07:00