Commit Graph

308 Commits

Author SHA1 Message Date
Herman Venter
bad3985f54 Clone completions when they complete composed effects (#2258)
Summary:
Release note: none

The main part of this PR is to ensure that completions and the effects they complete are always 1-1.

Along the way some bugs got fixed #2241.

This also includes a little side project: limiting the console spew when doing "yarn test-serializer --fast", which is something I do all the time and I'm much happier this way.
Pull Request resolved: https://github.com/facebook/prepack/pull/2258

Differential Revision: D8864448

Pulled By: hermanventer

fbshipit-source-id: a7f257a7e07211ecd6069b84330aa3305609c5d2
2018-07-16 13:56:10 -07:00
Sebastian Markbage
81bc21fad8 Delete node-cli Option and all the Node.js intrinsics (#2267)
Summary:
Since I'm adding a new experiment I figured I'd delete an equivalent sized one.

Last year I added an option that runs the Prepack program by invoking Node.js JS runtime which lets us prepack the whole module system and initialization. It's essentially a packager with perfect Node.js module resolution semantics. It did this by modeling Node's native environment as Prepack bindings.

This PR removes that whole option.

There's a few reasons why I don't think that worked out as a good idea.

- It's not solving a real need. It is hard to keep different module systems in tact. There is always something in the ecosystem that breaks down and using the canonical one solves that. However, in practice, if there is a need for bundling the ecosystem itself adapts to the toolchain. So it's not actually that hard to bundle up a CLI even with Webpack, even if it's strictly not 100% compatible, by tweaking a few downstream depenencies.

- Running the resulting bundle is tricky. The resulting bundle includes the JS parts of Node. This overlaps with what Node.js adds at runtime so it runs it twice. The ideal is actually to build a custom distribution of Node.js but this is generally overkill for what people want.

- Bindings change a lot. While Node.js's API notoriously doesn't change much. The internals do change a lot. By picking the API boundary in the middle of the internals of Node.js, it risks changing with any version. While technically observable changes, nobody else relies on these details. If this option was worth its weight, someone could probably maintain it but so far that has not been the case so we had to disable this option in CI to upgrade Node.

However, going forward I think there are alternative approaches we can explore.

- First class module system. This is something we really need at some point. A first class module system would be able to load Node.js module files from disk and package them up while excluding others. It doesn't have to be literally Node.js's module system. Close enough is ok. Especially as standards compliant ECMAScript modules get more popular. This lets us target compiling output that runs after Node's initialization.

- By introducing havocing and membranes in the boundaries, it becomes possible to initialize Node.js modules without actually knowing the internal of the boundaries.

- We've started optimizing residual functions which is much more interesting. However, this requires that code puts some constraints on how it works with its environment. It's not designed to be fully backwards compatible. That's probably a good thing but that also means that we can put constraints on the modules being Prepacked.

This removes the ability to prepack Prepack itself which is unfortunate but already wasn't being tested. To speed up Prepack itself, the [LLVM backend](https://github.com/facebook/prepack/pull/2264) seems much more useful if it can ever work on Prepack itself.
Pull Request resolved: https://github.com/facebook/prepack/pull/2267

Differential Revision: D8863788

Pulled By: sebmarkbage

fbshipit-source-id: d777ec9a95c8523b3386cfad553d9f691ec59074
2018-07-16 13:09:59 -07:00
Herman Venter
7c6dddf236 Make CircleCI fail if not enough 262 tests pass (#2263)
Summary:
Release note: fix test262 to fail CircleCI test if not enough tests pass

The check for the number of tests that pass returned 1 to its caller, who just ignored it and then returned 0. Instead of that, now just call process.exit(1) when the check fails.

Also updated the expected number of ES6 tests that pass. It appears that updating Babel had a positive effect on those. Possibly it also causes one more ES5 test to fail when running locally (but not on Circle). That might be because of an ES5 test that now times out and an ES6 test that now does not. I have not investigated this as it seems of little importance right now.
Pull Request resolved: https://github.com/facebook/prepack/pull/2263

Reviewed By: trueadm

Differential Revision: D8859210

Pulled By: hermanventer

fbshipit-source-id: 724dcde05927cc914f6f9517f14dc230b8b0ad2e
2018-07-16 08:44:59 -07:00
Dominic Gannaway
e170c37aaa Upgrade Prepack to Babel 7 (#2256)
Summary:
Release notes: upgrades Prepack to use Babel 7.0.0-beta.53

This is a big PR that updates all of Prepack to Babel 7. Babylon is now `babel/parser` and pretty much all of the the previous Babel packages are now located in scoped packages. I had to make a bunch of changes around Jest/Flow/Webpack to get this all working. The build times of building Prepack itself seem considerably faster (easily twice as fast locally). I followed most of the Babel 6 -> 7 upgrade guide from the Babel site in terms of changing nodes and type definitions to match the new ones.
Pull Request resolved: https://github.com/facebook/prepack/pull/2256

Differential Revision: D8850583

Pulled By: trueadm

fbshipit-source-id: 2d2aaec25c6a1ccd1ec0c08c5e7e2a71f78ac2d8
2018-07-14 09:55:18 -07:00
Dan Abramov
574411bb62 Ignore test262 for Prettier (#2242)
Summary:
This will fix CI on master. I forgot it's possible to land a change internally without it passing the CI checks.
Pull Request resolved: https://github.com/facebook/prepack/pull/2242

Differential Revision: D8801741

Pulled By: gaearon

fbshipit-source-id: 454fcb29e023a502557b67e0ed12a304c4e5fabc
2018-07-11 07:23:38 -07:00
Dan Abramov
ec37b77b6e Run Prettier for serializer tests too (#2234)
Summary:
Follow-up to https://github.com/facebook/prepack/pull/2212.
Pull Request resolved: https://github.com/facebook/prepack/pull/2234

Differential Revision: D8788834

Pulled By: gaearon

fbshipit-source-id: 08937736bed3df0ea13d5e7a3925fb2f58633d5c
2018-07-11 03:55:11 -07:00
Chris Blappert
91847ea6ba Make optimized functions produce compiler diagnostic on mutating non-… (#2175)
Summary:
…local state

The logic was already there for the React Compiler's invocations of evaluatePure, this PR just generalizes it a little to be used for optmized functions as well.

Additionally, adds the ability to check for compiler info/warning logs in test-runner + updates test-error-handler.

See #1589
Pull Request resolved: https://github.com/facebook/prepack/pull/2175

Differential Revision: D8786744

Pulled By: cblappert

fbshipit-source-id: 110a4732dd6bd129b4d91047c3c9a24f5249a5e9
2018-07-10 12:10:41 -07:00
Dan Abramov
66351887d3 Run Prettier checks on CI (#2212)
Summary:
This will fail CI if we forgot to run `yarn prettier` before committing.
We do the same in React repo. It prevents committing stale files that later cause unexpected changes.
Pull Request resolved: https://github.com/facebook/prepack/pull/2212

Differential Revision: D8784406

Pulled By: gaearon

fbshipit-source-id: ca948b8e088be8886c8ba865f280ba8d72750f69
2018-07-10 09:55:23 -07:00
Nikolai Tillmann
9f7d1bd425 Updating Flow to .76 (#2229)
Summary:
Release notes: None

Also removed timeout limit as we routinely exceed the default.
Pull Request resolved: https://github.com/facebook/prepack/pull/2229

Differential Revision: D8775206

Pulled By: NTillmann

fbshipit-source-id: 70f8521c7cd3c4de9b97bc9cb3c2c6694d7e1616
2018-07-09 17:25:15 -07:00
Herman Venter
dd1f18da0c Parameterize test262-runner with the expected counts required (#2228)
Summary:
Release note: Added --expectedCounts parameter to test262-runner so that success can depend on the value of the time-out and the version of the test suite that is used.
Pull Request resolved: https://github.com/facebook/prepack/pull/2228

Differential Revision: D8775828

Pulled By: hermanventer

fbshipit-source-id: 284bdb3526467f634f41a151e3995719af751e49
2018-07-09 16:54:38 -07:00
Herman Venter
366eca6ee1 Update the test262 submodule (#2216)
Summary:
Release note: Updated the test262 submodule to latest version

Also updated test262-runner.js to deal with time out errors showing up as diagnostics.

Filter out new tests that depend on errors being generated during the parsing phase. Since we depend on Babel for parsing, such issues are out of scope for us.
Pull Request resolved: https://github.com/facebook/prepack/pull/2216

Differential Revision: D8755005

Pulled By: hermanventer

fbshipit-source-id: 0c929904984d13efccbd3ad1ca125137ca275ef0
2018-07-06 15:10:10 -07:00
Dominic Gannaway
5f444abbda @allow-large-files [prepack][PR] Adds React native mocks (#2096)
Summary:
Release notes: adds React Native mocks to Prepack

This adds React Native mocks to Prepack and a few basic tests to demonstrate inlining of `View` and `Text`.
Closes https://github.com/facebook/prepack/pull/2096

Differential Revision: D8723932

Pulled By: NTillmann

fbshipit-source-id: 38bd265cd8935ebdf30266ec337378b4ea5b09d6
2018-07-03 14:44:41 -07:00
Herman Venter
466d19ddfd Special case "x === undefined || x === null" kind of expressions (#2188)
Summary:
Release note: special case expression simplification for Instant Render

When instant render is enabled turn x === undefined || x === null into __cannotBecomeObject(x) so that Instant Render can easily compile it down to a single byte code.
Closes https://github.com/facebook/prepack/pull/2188

Differential Revision: D8716594

Pulled By: hermanventer

fbshipit-source-id: bbcb25462f79852d8deac29bfed62e86745e5589
2018-07-02 13:39:35 -07:00
Dominic Gannaway
67a47fd48f Improve fb-www mocks objectWithoutProperties value by ensuring we store known values (#2194)
Summary:
Release notes: none

When the `objectWithoutProperties` mock was originally created, my knowledge of Prepack's internals wasn't as good as it was now. Now that I understand how AbstractObjectValues work, we can safely add the known values in `objectWithoutProperties` to the abstract backing object. The backing object was missing these values before and was an empty empty that was partial. This should give more data and value on our internal bundle, where before the values would be lost unnecessarily.
Closes https://github.com/facebook/prepack/pull/2194

Differential Revision: D8716289

Pulled By: trueadm

fbshipit-source-id: 451065473ea09943831f75c0bc15490e73c8d947
2018-07-02 13:11:28 -07:00
Dan Abramov
5159b0d832 Make React tests fast (#2187)
Summary:
Currently we have a single giant file with all tests, and a giant snapshot. This is both slow, and hard to work with and iterate on.

In this PR I will refactor our test setup.

- [x] Split it up into multiple files (gets the test running from 45s to 27s)
- [x] Run Prettier on test files
- [x] Split tests further for better performance
- [x] Make it possible to run one test file
- [x] Fix the issue with double test re-runs in watch mode on changes in the test file
- [x] Refactor error handling
- [x] Run Prettier on fixtures
- [x] Add a fast mode with `yarn test-react-fast <Filename>`
- [x] Fix double reruns on failure

Potential followups:
- [x] Figure out why test interruption broke (need https://github.com/facebook/jest/issues/6599 and https://github.com/facebook/jest/issues/6598 fixed)
- [x] Revisit weird things like `this['React']` assignment with a funny comment in every test
Closes https://github.com/facebook/prepack/pull/2187

Differential Revision: D8713639

Pulled By: gaearon

fbshipit-source-id: 5edbfa4e61610ecafff17c0e5e7f84d44cd51168
2018-07-02 11:25:58 -07:00
Nikolai Tillmann
2e2b92eec0 Adding --instantRender mode. (#2178)
Summary:
Release notes: None

Tweaking some behaviors to help with Instant Render automation.
This leaves behind some TODOs in the code, but unblock me for now.
Closes https://github.com/facebook/prepack/pull/2178

Differential Revision: D8689796

Pulled By: NTillmann

fbshipit-source-id: f919a8b6bbfb63513bb9467027676e0ba7d4230e
2018-06-28 20:53:43 -07:00
Dominic Gannaway
9905f613d6 Fixes nested evaluatePure calls and React nested optimized closure side-effect detection (#2166)
Summary:
Release notes: none

Fixes nested `evaluatePure` calls, where before they would collide and overwrite one another. Also ensure React reconciler uses side-effect detection on nested optimized closures. This fixes a React test which should have been failing before, but wasn't.
Closes https://github.com/facebook/prepack/pull/2166

Differential Revision: D8681422

Pulled By: trueadm

fbshipit-source-id: 8941812407d1bda5af0343a09210aeff24a36cff
2018-06-28 13:26:00 -07:00
Herman Venter
8554d2d1ee Fix test runner and don't swallow invariant failures (#2155)
Summary:
Release note: Fix test runner and don't swallow invariant failures

The recent changes to make the serializer test runner deal with promises, caused it to list every test that follows a failing test as also failing.

I've also noticed that invariant failures can get swallowed. And as a result of that some test cases that should have failed with false invariants showed up as passing.

Those failures were recently introduced by PR #2134. It boils down to a single line fix, which is also included with this.
Closes https://github.com/facebook/prepack/pull/2155

Differential Revision: D8629298

Pulled By: hermanventer

fbshipit-source-id: 467f7efdf119ea9d29083d4e41054e583b38a1ff
2018-06-25 18:41:59 -07:00
Dominic Gannaway
bfffc7ac38 Tidy up React logic, pulled from #2096 (#2163)
Summary:
Release notes: none

To make https://github.com/facebook/prepack/pull/2096 easier to review, this pulls out the tidy ups from that PR.

- fix typo on function name `mergeAdjacentJSONTextNodes`
- move ReactDOM mock logic into its own file
Closes https://github.com/facebook/prepack/pull/2163

Differential Revision: D8625051

Pulled By: trueadm

fbshipit-source-id: 5345cc26f5c613b4afbb1c768213fd84caf5ebab
2018-06-25 16:00:58 -07:00
Herman Venter
cc1e081854 Update Flow version and fix newly reported Flow errors. (#2150)
Summary:
Release note: update Flow version

Require latest Flow version and fix newly reported type errors.
Closes https://github.com/facebook/prepack/pull/2150

Differential Revision: D8592311

Pulled By: hermanventer

fbshipit-source-id: 98b7a7de81a1aae18973ccc858cacfaa02d43f8e
2018-06-22 11:25:50 -07:00
Dominic Gannaway
18e69904d5 Allow Object.assign to continue evaluation in pure scope (#2068)
Summary:
Release notes: in pure mode, allow Object.assign to continue evaluation rather than throwing FatalErrors

This PR adds bail-out support of `Object.assign` sources within the `Object.assign` implementation. This allows us to continue evaluation in pure scope without bailing out of the Object.assign entirely (like we currently do) upon a FatalError occurring. Given we have snapshotting in `Object.assign`, we don't need to havoc the sources.

This allows us to inline and evaluate far more within our internal bundles. Fixes https://github.com/facebook/prepack/issues/2064
Closes https://github.com/facebook/prepack/pull/2068

Differential Revision: D8579441

Pulled By: trueadm

fbshipit-source-id: 0e97b54e0c8af63f1e3cd08fca6c7f375ee3c615
2018-06-21 16:10:40 -07:00
Manas
958fa43d6c test-runner now supports promises (#2115)
Summary:
Release note: none

Attempts adding support for promises in test-runner.js. `inspect` can now return Promises, which will be resolved before checking it value.
Closes https://github.com/facebook/prepack/pull/2115

Differential Revision: D8550825

Pulled By: hermanventer

fbshipit-source-id: 3f9781f6e34016dcb61bd436400a1bfb51932452
2018-06-20 13:55:18 -07:00
Dominic Gannaway
f2219fd33c Handle intrinsic values created by React that have the same name (#2126)
Summary:
Release notes: none

There was a bug, where React abstract object values with the same intrinsic name were incorrectly being de-duped and re-used. This is a normal expected Prepack optimization, but it actually breaks React components that expect to be able to create many values with the same intrinsic name. We now mark such objects and ensure they do not correctly return `true` from `equals()`. Fixes https://github.com/facebook/prepack/issues/2089
Closes https://github.com/facebook/prepack/pull/2126

Differential Revision: D8448171

Pulled By: trueadm

fbshipit-source-id: d21fddd70576e6e55c41070ac43ce2f58a059e7a
2018-06-15 09:09:45 -07:00
Dominic Gannaway
0cc82dc875 Move ReactElement sanitization to the serialization phase (#2123)
Summary:
Release notes: none

This PR moves the logic of sanitizing ReactElements for `firstRenderOnly` mode to the serialization phase instead of during reconciliation. The plan is to create a follow up PR that introduces a new phase after the visitor phase, that skips values that were detected as dead code once the visitor stage finishes, but that's not in scope for this PR.
Closes https://github.com/facebook/prepack/pull/2123

Differential Revision: D8435440

Pulled By: trueadm

fbshipit-source-id: f442525e663a7bc0f9608b96eb7d7a2389a707b7
2018-06-15 06:53:25 -07:00
Dominic Gannaway
491ec2ad26 Adds regression tests for issue 2056 (#2124)
Summary:
Release notes: none

It turns out that the tests in https://github.com/facebook/prepack/issues/2056 now pass on master, so this adds regression tests for them. Fixes #2056.
Closes https://github.com/facebook/prepack/pull/2124

Differential Revision: D8432504

Pulled By: trueadm

fbshipit-source-id: fce78b4ecfc9cee55cf70868557a3eacac635867
2018-06-14 16:03:18 -07:00
Dominic Gannaway
0d7807d871 Nested functions bindings (#2117)
Summary:
Release notes: fixes serialization of bindings when shared between optimized functions

This PR fixes a long standing bug with nested optimized functions where bindings would incorrectly serialize to the main body scope when the binding was shared between nested optimized functions and their parent optimized function scopes. This allows us to not skip 2 React tests and I also added a serializer regression test that demonstrates the same problem so we don't regress.
Closes https://github.com/facebook/prepack/pull/2117

Differential Revision: D8408712

Pulled By: trueadm

fbshipit-source-id: 0e0a306f9195fcb5b57fa7f8cef1c65dbef4998f
2018-06-13 16:27:32 -07:00
Nikolai Tillmann
df757a6a28 Improving compiler diagnostics output (#2104)
Summary:
Release notes: None

In particular, no longer claim that there were "errors" when there in fact none.
Closes https://github.com/facebook/prepack/pull/2104

Differential Revision: D8371246

Pulled By: NTillmann

fbshipit-source-id: b33519bf8a2b53150b24ea6f7db9b43b20e7dd1f
2018-06-13 01:11:14 -07:00
Dominic Gannaway
3bd3ecc072 Support logical operator unfolding in React reconcilation (#2091)
Summary:
Release notes: React compiler supports unfolding && and || logical expressions

This adds support for `&&` and `||` logical abstract value unfolding.
Closes https://github.com/facebook/prepack/pull/2091

Differential Revision: D8386493

Pulled By: trueadm

fbshipit-source-id: 3def85ac912906ada087a99c27f91ad80897c55e
2018-06-12 18:28:04 -07:00
Dominic Gannaway
0d762f7ab5 Add lazy ReactElement creation when in conditionals (#2107)
Summary:
Release notes: none

This is a long standing fix, where ReactElements should be created lazily but are currently not done so. To do this, we now use the `temporalAlias` code paths on lazy branched ReactElements to ensure they are emitted as temporal entries when we "branch" (i.e. conditional) and have many possible routes where ReactElements may or may not be created.

Fixes https://github.com/facebook/prepack/issues/2113. Depends on https://github.com/facebook/prepack/pull/2112
Closes https://github.com/facebook/prepack/pull/2107

Differential Revision: D8383327

Pulled By: trueadm

fbshipit-source-id: bbcff45ddd07406b18bcddce2de0279fb52da1a1
2018-06-12 12:39:43 -07:00
Dominic Gannaway
05a7730b99 Optimize ReactElement children with equivalence logic (#2114)
Summary:
Release notes: improves ReactElement creation by re-using ReactElement nodes where possible

We already have a pretty good ReactElement equivalence system to re-use ReactElements. We weren't using it to its full power though. When we have nested ReactElements, we don't use the equivalence system at all, meaning we duplicate lots of ReactElements when we can re-use.

This is a nice performance optimization. I've added a test that should prevent regressions here too.
Closes https://github.com/facebook/prepack/pull/2114

Differential Revision: D8381595

Pulled By: trueadm

fbshipit-source-id: befabd04326a162f8ab6a00e089cdada052cf6c8
2018-06-12 11:09:19 -07:00
Dominic Gannaway
6fc554f5c3 Fix react tests (#2109)
Summary:
Release notes: none

Fixes the React tests, not to skip.
Closes https://github.com/facebook/prepack/pull/2109

Differential Revision: D8359944

Pulled By: trueadm

fbshipit-source-id: bf1ed3a19fb1c5a949e726a4faa38bfecee69f0a
2018-06-11 11:59:21 -07:00
Dominic Gannaway
e4875197fb Improve inlining of React.createContext (#2098)
Summary:
Release notes: none

Whilst working on adding React Native mocks, I ran into cases where context should be inlining but it wasn't. It now is inlining far better, with more test coverage. Furthermore, we now have a new config flag to pass to `__optimizeReactComponentTree`, in the case of `isRoot` to state that the tree is a root component tree (rather than a a branch of another tree).
Closes https://github.com/facebook/prepack/pull/2098

Differential Revision: D8348381

Pulled By: trueadm

fbshipit-source-id: 5e01bd77437e8bc3d1f22ff47d668897152203a0
2018-06-11 04:36:50 -07:00
Peter van der Zee
485ea766fa Fix os.cpus() and worker count in prepack test runner
Summary:
Turns out os.cpus() can return [] and undefined.

Additionally, it seems to me like any number below 4 could lead to an empty pool so I tried to address that too.

Reviewed By: NTillmann

Differential Revision: D8332896

fbshipit-source-id: 60e082a4f0d18e72f95b76732a50adeccb2d333d
2018-06-11 00:56:05 -07:00
Andres Suarez
f20de93335 Prettier 1.13.4 fixes
Reviewed By: trueadm

Differential Revision: D8301297

fbshipit-source-id: f2fb9562680aa0c1de717f8f162ae8cb611c27f4
2018-06-06 12:49:59 -07:00
Dominic Gannaway
c551500aeb Call React createDefaultPropsHelper creates function on init (#2087)
Summary:
Release notes: none

This fixes an issue where `createDefaultPropsHelper` gets created in a branch of effects, and is cached on the `realm`. Instead `createDefaultPropsHelper` should get created during the init phase, so the function is accessible throughout the entire lifecycle of the realm.
Closes https://github.com/facebook/prepack/pull/2087

Differential Revision: D8290010

Pulled By: trueadm

fbshipit-source-id: 324035cdd3c8a951c44849e1ccbfca9798a551b0
2018-06-05 17:54:45 -07:00
Dominic Gannaway
318da6c7f6 Refactor of createElement props/config to fix bugs + use snapshotting
Summary:
Release notes: fixes a range of spread bugs with ReactElements

This is a very important PR for React reconciliation, it fixes many undiscovered bugs and adds a huge amount of test coverage that was previously missing.

Whilst testing quite complex cases of JSX spreads in combination with defaultProps on our internal bundle I noticed that there were some bugs appearing, but because the branches where these bugs were appearing were not used on firstRender, it meant we got away with it on our internal tests.

We now use snapshotting and properly evaluateForEffects when recovering from `Object.assign` with ReactElement creation of config/props. We also properly use the `temporalAlias` to ensure we reference the correct object.
Closes https://github.com/facebook/prepack/pull/2070

Differential Revision: D8243793

Pulled By: trueadm

fbshipit-source-id: e8c37aa6750c0a6d41f12249d8872004da3ab3a6
2018-06-02 06:34:27 -07:00
Dominic Gannaway
679b7d092e Upgrade ESlint to support ES2018
Summary:
Release notes: none

Make our linter use the latest `ecmaVersion`. https://eslint.org/docs/user-guide/configuring#deprecated
Closes https://github.com/facebook/prepack/pull/2069

Differential Revision: D8230681

Pulled By: trueadm

fbshipit-source-id: fddaeef4692cf45e929f243a7255518705a25727
2018-05-31 17:04:35 -07:00
Dominic Gannaway
bcf7255ce3 Do not emit final property assignments when havocing
Summary:
Release notes: none

When in strict mode, emitting property assignments to a frozen object (ReactElement in this case) causes a runtime error. We shouldn't be emitting ReactElement properties when we havoc the object. Unfortunately, we can't do this to all final objects, because our internal snapshot test fails when doing this (because the final object has properties that are conditional and thus delayed, so we need all its bindings to be "flushed" at the point of havocing). As a more thorough future fix, we should probably add a separate codepath for serializing objects that are final (we delay the entire object being emitted until all its properties are ready, like the ReactElement serializer does).

Interestingly, the output contains an unused variable that should be removed NTillmann?

```js
var _0 = function (props, context) {
    "use strict";

    var _J = props;
    var _$0 = _J.b;

    var _1 = _$0 !== null;

    if (_1) {
      var _$1 = _J.b;
      var _$2 = _$1.x;

      var _5 = _$2 !== null;

      if (_5) {
        var _$3 = _J.b;
        var _$4 = _$3.x;
      }
    }

    var _$5 = _J.c;
    var _$6 = _J.someAbstractFunction;

    var _A = _1 ? _5 ? _$4 : null : null;

    var _8 = {  // <-- why has this not been removed? can we not mark the entry as "pure"
      a: 1,
      b: _A,
      c: _$5
    };
    _8.a = 1;
    _8.b = _A;
    _8.c = _$5;

    var _F = <div a={1} b={_A} c={_$5} />;

    var _$7 = props.someAbstractFunction(_F);

    return _F;
  };
```
Closes https://github.com/facebook/prepack/pull/2065

Differential Revision: D8221498

Pulled By: trueadm

fbshipit-source-id: e508cba2e930bec9c913efae3c653637671098c6
2018-05-31 07:27:44 -07:00
Dominic Gannaway
d94f231718 React option better stats
Summary:
Release notes: adds `reactOptimizeNestedFunctions` flag to enable nested optimized functions from React components

This PR adds output for components that fail to inline (during evaluation process) and adds a flag so we can enable/disable nested optimized functions in React components (from things like unknown array map functions).
Closes https://github.com/facebook/prepack/pull/2054

Differential Revision: D8202653

Pulled By: trueadm

fbshipit-source-id: 9ea95720e5296e602068ca4fe111ab303b8b24fc
2018-05-30 14:32:13 -07:00
Dominic Gannaway
fdc7ba549f Cleanup of all the React reconciler logic + remove mutations on ReactElements
Summary:
Release notes: none

This PR is a general spring cleaning of all the React logic. Nothing is fixed, but the logic for many of the aspects of the React reconciliation have been simplified and tidied up.

- I've removed all cases of mutating ReactElements, we now create new ReactElements instead of mutating – because, well, ReactElements are immutable (as are props).
- Removed ReactSerializerState and moved the logic that previous existed into `realm.react`.
- Simplified the branching logic of the reconciler so we no longer need to pass around state and instead use the existing conditional logic.

Manually tested on all our internal bundles are we have no failures.
Closes https://github.com/facebook/prepack/pull/2039

Reviewed By: gaearon

Differential Revision: D8205619

Pulled By: trueadm

fbshipit-source-id: a84c363038086b490d761dbe18711d617058f05c
2018-05-30 12:39:22 -07:00
Dominic Gannaway
bd29f451fd Tidy up simple tests and fix refuseSerialization bug
Summary:
Release note: none

This PR remove `firstRenderOnly` from a bunch of tests that shouldn't have had it and adds a new test for a big with `props` being incorrectly marked for `refuseSerialization` – `props` can be serialialized without the ReactElement, and the test shows how this might happen.
Closes https://github.com/facebook/prepack/pull/2057

Differential Revision: D8203483

Pulled By: gaearon

fbshipit-source-id: fbfb9cc3bbdadaba5884f87319cb5b54e4a0657a
2018-05-30 10:49:05 -07:00
Herman Venter
26290ddd00 Fix lint errors
Summary:
Release note: none

Fix lint errors that came our way via an internal check in.
Closes https://github.com/facebook/prepack/pull/2052

Differential Revision: D8197681

Pulled By: hermanventer

fbshipit-source-id: fdc481228239dcc1eeafc904536188e25289162a
2018-05-29 17:48:22 -07:00
Dan Abramov
5d45e5a7eb Fix test output
Summary: This ensures failing output for Prepack gets proxied into the actual logs in terminal and Sandcastle. That was the case for Jest, but not for Prepack itself. This surfaces the real error in D8188966, for example.

Reviewed By: sophiebits

Differential Revision: D8191668

fbshipit-source-id: d0e3e9ddc1f7b38157fc57a010026de9bb0ec79a
2018-05-29 14:39:17 -07:00
Dominic Gannaway
829acd5f64 Properly handle defaultProps with creation of ReactElements
Summary:
Release notes: none

After discussions last night with sebmarkbage, I noticed that we apply defaultProps in the wrong place when the config is partial object or an abstract object. This now uses a helper function, which is injected once for the entire bundle, that handles `defaultProps` cases as a temporal function entry. Added a regression test too.
Closes https://github.com/facebook/prepack/pull/2036

Differential Revision: D8175799

Pulled By: trueadm

fbshipit-source-id: b6bb4f30ee07f0bd9ac07fc91018c26936696f4b
2018-05-26 10:30:33 -07:00
Dominic Gannaway
47f84b405a Re-factor of the React createElement logic
Summary:
Release notes: none

Now that we have snapshotting from Object.assign and ToObject for abstracts, we can now upgrade the ReactElement creation logic, simplifying a bunch of routes which actually resulted in a bunch of components inlining in tests where they didn't before. Furthermore, it allows us to tighten up the Flow typings in the React reconciler and tidy up some of the checks for `key`s or `ref`s logic, which was a bit hard to read before and didn't take into account objects with multiple values in their values domain. This also fixes a bug with abstract conditional component types not getting the deafultProps values correctly.
Closes https://github.com/facebook/prepack/pull/1996

Differential Revision: D8172083

Pulled By: trueadm

fbshipit-source-id: 0a8a1e0631883c92e914aba1308a109b3afda137
2018-05-25 18:34:12 -07:00
Dominic Gannaway
3d35fc8cbd Fix react tests
Summary:
Release notes: none

An test only was accidentally merged to master.
Closes https://github.com/facebook/prepack/pull/2014

Differential Revision: D8134882

Pulled By: trueadm

fbshipit-source-id: 55194aa25aea409b6163c04f3d222f77c42acc6c
2018-05-24 02:55:31 -07:00
Dominic Gannaway
74ae4f86dd Add ReactDOM.createPortal inlining
Summary:
Release notes: adds support for ReactDOM.createPortal inlining

Allows the React reconciler to inline components passed to ReactDOM.createPortal.
Closes https://github.com/facebook/prepack/pull/2006

Differential Revision: D8125418

Pulled By: trueadm

fbshipit-source-id: a25a2c23d1dcaa2edaada6fecb39ef80bb829cff
2018-05-23 15:24:35 -07:00
Dominic Gannaway
87591341b1 Add __doNotRender flag to React reconcilation
Summary:
Release notes: opt out of optimizing a React component in a tree with `__doNotRender`

This PR makes it possible to opt out of a single component in a React component tree by detecting a `__doNotRender` flag. For example:

```js
function MyComponent(props) {
   ...
}

MyComponent.__doNotRender = true;

class MyComponent extends React.Component {
  render() {
    ...
  }
}

MyComponent.__doNotRender = true;
```
Closes https://github.com/facebook/prepack/pull/2004

Differential Revision: D8123009

Pulled By: trueadm

fbshipit-source-id: d5fc54aea2ea1253e260e41c1fb7d4f2d4717ffd
2018-05-23 11:53:46 -07:00
Dominic Gannaway
cde1af298d Do not mutate arrays or ReactElements during React reconciliation
Summary:
Release notes: none

This fixes an issue that we were experiencing, that turned out to be the correct fix after looking at https://github.com/facebook/prepack/pull/1997. We shouldn't mutate arrays in the reconciliation process, instead we should create new ones when we have new values. Also, we should ensure that we don't mutate ReactElements during reconciliation too, instead we should just create new ones. Mutating existing objects and values breaks down completely when we enter nested effects that need to re-evaluate the same original values, so this fixes a bunch of internal issues we were seeing on our internal FB bundle.
Closes https://github.com/facebook/prepack/pull/1999

Differential Revision: D8105499

Pulled By: trueadm

fbshipit-source-id: 4e6ceb8b02c886c42156a8903c347765f101c840
2018-05-22 16:35:40 -07:00
Dominic Gannaway
393eba15ad Ensures all serializer test case output passes linting validation
Summary:
Release notes: all serializer tests now get linted via ESlint for correct output

This PR is pretty gigantic, but almost 99% of it is changing all the serializer tests so they pass the linting rules – which means that there must be no undefined variables or if they are, they are explicitly accesses via `global`. Furthermore, the linting also checks to ensure that all variables are defined before they are used.

Also I added a regression test `conditions3` that further validates some complex cases I was seeing fail in other cases. The ESlint config is also in its own module so it can be shared between `debug-fb-www`.
Closes https://github.com/facebook/prepack/pull/1998

Differential Revision: D8099445

Pulled By: trueadm

fbshipit-source-id: 4a03c57beb51e394bc7b334728090b9fc515eca8
2018-05-22 15:41:31 -07:00