Commit Graph

69 Commits

Author SHA1 Message Date
Dominic Gannaway
d38f0570c2 Fixes a bunch of serialization bugs
Summary:
Release notes: none

This PR came about from trying to fix https://github.com/facebook/prepack/issues/1771. This PR fails on the tests still, so I need some help getting them resolved.

- `_emitProperty` should account for the fact a `key` can be an `AbstractValue`, thus needs to serialize the value.
- `visitObjectPropertiesWithComputedNames` in the visitor and `_getNestedAbstractValues` in the serializer both need to take into account cases where `alternate` and `consequent` might not be `AbstractValue`s.
Closes https://github.com/facebook/prepack/pull/1781

Differential Revision: D7777483

Pulled By: trueadm

fbshipit-source-id: 1b94489ec9c800a68414031e0bc63b06061fe559
2018-04-26 14:22:19 -07:00
Dominic Gannaway
9e5cc34819 Fixes an issue with getDerivedStateFromProps
Summary:
Release notes: none

When doing `Object.assign` in `getDerivedStateFromProps`, we need to add back in the fallback for when it might fail otherwise we end up triggering invariants. This fixes https://github.com/facebook/prepack/issues/1773
Closes https://github.com/facebook/prepack/pull/1780

Differential Revision: D7773190

Pulled By: trueadm

fbshipit-source-id: 2539f01cfde3a65136a6e9947a4620dfc81a371a
2018-04-26 01:58:46 -07:00
Dominic Gannaway
fc371688e9 Fix hoisting invariant bug
Summary:
Release notes: none

There was a case where an invariant was firing in the hoisting logic due to a binding value being undefined. This PR stops the invariant from firing in such cases, and includes the regression test. I also found another issue in the evaluatedReactNode debugging output and fixed that too so it was easier to see what was going on with this and other issues.

This fixes https://github.com/facebook/prepack/issues/1775
Closes https://github.com/facebook/prepack/pull/1779

Differential Revision: D7763057

Pulled By: trueadm

fbshipit-source-id: 61c866f7cb7322f5d884262adb85613c97cfa4ca
2018-04-26 01:58:46 -07:00
Dominic Gannaway
d12bcef03e Better handling of this with simple React class components
Summary:
Release notes: none

This fixes bugs around detecting independent dangling `this` keywords in methods of a React class component and correctly bailing out upon finding them. This is typically used in cases where we'd want to bail out, for example:

```js
let self = this;
let handleClick = function () { console.log(self.x) };
return <div onClick={handleClick} />
```

or:

```js
let handleClick = function () { console.log(this.x) };
return <div onClick={handleClick.bind(this)} />
```
Closes https://github.com/facebook/prepack/pull/1777

Differential Revision: D7757435

Pulled By: trueadm

fbshipit-source-id: b06fe29a3ac4a44bdf2b8a7c6e9457e5801b32b7
2018-04-25 04:59:14 -07:00
Dominic Gannaway
2861f78231 Properly strips on* events in first render and fixes tests
Summary:
Release notes: fixes a regression where on* events would not be stripped in React firstRender mode

This PR fixes a recent regression in the stripping of onEvent names in React compiler's firstRender mode. The associated tests have been updated so the snapshots should pick up this regression in the future.
Closes https://github.com/facebook/prepack/pull/1774

Differential Revision: D7747737

Pulled By: trueadm

fbshipit-source-id: e0dd65a7e4d73844c499d1d8b2f9ae8046bfec2b
2018-04-24 13:10:43 -07:00
Dominic Gannaway
b798f32ef2 Fold Relay components via createFragmentContainer for firstRenderOnly
Summary:
Release notes: none

This adds the functionality to fold/inline ReactRelay components via `createFragmentContainer`. This is for first-render only for now.
Closes https://github.com/facebook/prepack/pull/1745

Differential Revision: D7686225

Pulled By: trueadm

fbshipit-source-id: 7eb546ff70e92b60bcc1abb69c0cc5091926c012
2018-04-19 14:14:26 -07:00
Dominic Gannaway
9123227e45 Fixes Prettier issues on master
Summary:
Release notes: none

Fixes the current lint issues on master regarding Prettier.
Closes https://github.com/facebook/prepack/pull/1761

Differential Revision: D7686530

Pulled By: trueadm

fbshipit-source-id: 0885854c3cca409d47d4980735f56bd794f55606
2018-04-19 08:53:06 -07:00
Dominic Gannaway
d72ce06580 Support null/undefined config object for React.createElement
Summary:
Release notes: none

When a `null` or `undefined` value is passed as the `config` for `createElement`, then we need to create an empty object to be used instead.
Closes https://github.com/facebook/prepack/pull/1759

Differential Revision: D7686087

Pulled By: trueadm

fbshipit-source-id: a8eb917f38ca3afe881af08d07fe8be0943b0a1f
2018-04-19 07:08:41 -07:00
Dominic Gannaway
d109852ffa Ensure we apply nested closure effects in the right order
Summary:
Release notes: none

Ensure we apply the nested closure effects in the right order. This was the underlying bug after doing much digging.

Furthermore, I added case where this fails. I also found that the ReactElement code was causing issues at one point (I forgot to add the props, type, ref and key as dependencies), but that wasn't needed in the end for this fix, but I thought it best to keep those fixes in.

I also had to make a change to the JSON tester as it was incorrectly failing a test because the function closures were not 1:1, which they're not meant to be.
Closes https://github.com/facebook/prepack/pull/1743

Differential Revision: D7686048

Pulled By: trueadm

fbshipit-source-id: 8cf7faed51c86720e519abbbad209820e7e02dc4
2018-04-19 07:08:40 -07:00
Dominic Gannaway
d811e0c567 Handle cases where gDSFP is given an abstract state
Summary:
Release notes: none

When working on internal projects, I found cases where the `getDerivedStateFromProps` would throw a FatalError because the partial state wasn't an abstract object value or object value. In this case we can see that the abstract value is a conditional and handle the paths to ensure we get the correct results without failing.
Closes https://github.com/facebook/prepack/pull/1737

Differential Revision: D7615094

Pulled By: trueadm

fbshipit-source-id: 5c868a46936a108c277ac52c2675feabc1f4df8c
2018-04-13 03:00:04 -07:00
Nikolai Tillmann
7579c5fc0b Introducting new option --invariantLevel NUMBER and dropping --omitInvariants
Summary:
Release notes: Introducting new option --invariantLevel NUMBER and dropping --omitInvariants

The new default is invariant level 0, which corresponds to the old --omitInvariants.
Level 1 is roughly what we used to do: Check invariants on (derived) abstract values.
Level 2 implements #1180: Checking that all accesses to built-ins do what Prepack expects them to do, including checks for when properties on built-ins are absent.
Level 3 adds checks for internal consistency, basically an internal debug level.

The serializer tests now run with the highest invariant level by default. The added invariants found a few issues that got addressed, including:
- Prepack exposes a TypedArray prototype, which is not a real thing. It's now marked as `__refuseSerialization`, and no invariants are emitted for such things.
- Global variables / properties on the global object are special. Those are not yet handled at level 2.
- Accesses to Prepack magic functions that generally start with `__` should not produce invariant checks.
- Magic code generation for loops should not take into account objects that are `__refuseSerialization`.
- All invariant statements get a unique id to make it easier to locate them.
- I marked some test cases which depend on counting occurrences in the output as "// omit invariants", as the additional invariants increased some such counts.

As part of testing, I also found it necessary to make the --invariantMode more useful; it now also allows specifying nativeLoggingHook which is the preferred way of logging in React Native.

To reduce the number of checks by a few orders of magnitude in practice, each property is only checked on first access. This is tracked by a global variable `__checkedBindings`.

This pull requests incorporates all aspects of the #1709 (which I abandoned).
Closes https://github.com/facebook/prepack/pull/1724

Reviewed By: simonhj

Differential Revision: D7575091

Pulled By: NTillmann

fbshipit-source-id: 585cd224ce66882f8e5f27d88c1ad08afeb96ee1
2018-04-12 11:58:25 -07:00
Dominic Gannaway
cd30805c65 Ensure React component write effects do not conflict one another
Summary:
Release notes: none

This PR adds some sanity around React components roots that when render, mutate the same of bindings as other React component roots. This is currently not supported and thus safely bails out and continues.
Closes https://github.com/facebook/prepack/pull/1736

Differential Revision: D7600373

Pulled By: trueadm

fbshipit-source-id: fe2b2b3055fa3c1b28668da6d67bca3826431eb6
2018-04-12 09:55:14 -07:00
Dominic Gannaway
8264cfffd7 Adds createRef and forwardRef to the React compiler
Summary:
Release notes: Adds`createRef` and `forwardRef` to the React compiler

This PR adds both features from React 16.3, including full inlining of forwardRef functions.
Closes https://github.com/facebook/prepack/pull/1731

Differential Revision: D7599780

Pulled By: trueadm

fbshipit-source-id: 50458546c7a4374baea7fa80feb21262dd5692af
2018-04-12 06:34:44 -07:00
Dominic Gannaway
6ec280b8c8 Adds getDerivedStateFromProps support and updates React version deps
Summary:
Release notes: adds React 16.3 `getDerivedStateFromProps` support to the React compiler

This PR adds support for the React 16.3 `getDerivedStateFromProps` lifecycle event on class components. I've also updated the React testing dependencies to 16.3.1. I also extended the `componentWillMount` logic to support `UNSAFE_componentWillMount` too.
Closes https://github.com/facebook/prepack/pull/1730

Differential Revision: D7586378

Pulled By: trueadm

fbshipit-source-id: 895e74ca86eb9ff9ad04aa93f021c107f08a7b9f
2018-04-11 10:11:33 -07:00
Dominic Gannaway
1af47e55e2 Internal bootloader changes
Summary:
Release notes: none

Some internal changes to ensure `Bootloader.loadModules()` global stays as is and doesn't get destructured. Also changed the incorrect usage of `context.$Realm.generator.derive` in the mocks.
Closes https://github.com/facebook/prepack/pull/1726

Differential Revision: D7578301

Pulled By: trueadm

fbshipit-source-id: dd7dce3e46ff01b10eb9206a1ed5d94871ae93fd
2018-04-10 16:10:50 -07:00
Dominic Gannaway
923df52786 Adds more replace React test covering "this"
Summary:
Release notes: none

Adds more tests to ensure we don't regress in some cases.
Closes https://github.com/facebook/prepack/pull/1649

Differential Revision: D7392527

Pulled By: trueadm

fbshipit-source-id: 0b34bfd741a5de7ea434f6e3c30f15dab983482e
2018-03-24 08:35:51 -07:00
Dominic Gannaway
156c30f401 Support inlining dynamic ReactElement "type" fields
Summary:
Release notes: none

This adds a really cool feature – dynamic ReactElement type. As per a conversation in Messenger yesterday by gaearon, it got me thinking about how we might "simplify" recursively on a conditional in complex cases and I decided it was probably worth adding to inline components. This PR makes it possible to inline component trees without having to break out when the type is an abstract conditional.
Closes https://github.com/facebook/prepack/pull/1647

Differential Revision: D7392497

Pulled By: trueadm

fbshipit-source-id: 170ae4829bd407410d8882c874144516cfd01190
2018-03-24 07:57:53 -07:00
Dominic Gannaway
3dabacf56e Add nested optimized function support to React reconciler
Summary:
Release notes: none

This PR adds nested optimized function support and bug fixes around them to the React reconciler.

The tests added that fail have been skipped for now until we have the ability to properly serialize nested optimized functions.
Closes https://github.com/facebook/prepack/pull/1614

Differential Revision: D7366102

Pulled By: trueadm

fbshipit-source-id: c18c5a470a31b905a76155e006767f8ec7a73afa
2018-03-22 10:54:42 -07:00
Nikolai Tillmann
032f71403f Removing --abstractEffectsInAdditionalFunctions option
Summary:
Release notes: Removing --abstractEffectsInAdditionalFunctions option

It is now the new default, as nothing seems to depend on the old behavior.
Closes https://github.com/facebook/prepack/pull/1623

Differential Revision: D7342083

Pulled By: NTillmann

fbshipit-source-id: c02d13bddd0ff3d8a113a6a5a83c1bf35c96ba4d
2018-03-20 15:04:24 -07:00
Dominic Gannaway
e9fe2a5e7c Allow NewExpression constructor to recover in pure wrapper
Summary:
Release notes: none

It's common for a `new Something()` call to exist in pure wrappers where `Something` is an abstract value. Currently, this fails with a FatalError with no recovery. This PR adds a recover for this when in a pure wrapper so we can continue evaluating.
Closes https://github.com/facebook/prepack/pull/1590

Differential Revision: D7271876

Pulled By: trueadm

fbshipit-source-id: fc5192af6b356b7df9eb2f147bd8b53fe3790942
2018-03-14 08:01:24 -07:00
Dominic Gannaway
46061fc186 Protect against common firstRender issues
Summary:
Release notes: none

firstRender can fail when `Function.prototype.bind` is passed around because the firstRender removes the class component entirely, along with any concept of state etc. To prevent outputting the incorrect value, we now check for bind and if we're given something that is completely abstract as a child from a render, we bail out in that case too.
Closes https://github.com/facebook/prepack/pull/1573

Differential Revision: D7248829

Pulled By: trueadm

fbshipit-source-id: eebd7e6565352a37026928a20944377bb06129f5
2018-03-12 17:46:40 -07:00
Dominic Gannaway
eab76537fa Fixes a visitor issue for React library
Summary:
Release notes: none

Found an issue on REPL: https://goo.gl/Qz46FJ

This fixes it along with a test.
Closes https://github.com/facebook/prepack/pull/1564

Differential Revision: D7231968

Pulled By: trueadm

fbshipit-source-id: c3ceff7d345f1a48e6fdeccfeaed6740383fbd40
2018-03-12 05:05:09 -07:00
Dominic Gannaway
21fcfb2a09 Adds React.createContext API support
Summary:
Release notes: none

Adds React.createContext support to the React compiler. Updates Yarn dependencies to use React 16.3 pre-release version so tests can validate new API works with the compiler.
Closes https://github.com/facebook/prepack/pull/1548

Differential Revision: D7209302

Pulled By: trueadm

fbshipit-source-id: fff360ee19d4d9fee6e27b738658d9076449da4b
2018-03-11 13:12:41 -07:00
Dominic Gannaway
8181c419da Detect dead additional functions and do not serialize them
Summary:
Release notes: none

When we evaluate multiple additional functions, they might remove other additional functions that were defined as additional functions. This causes a serializer issue. If we check if they have info from the visitor we can avoid hitting an invariant. This fixes one of the issues flagged in https://github.com/facebook/prepack/pull/1550, thus pulling in the test that was failing from the PR.

This PR is rebased on https://github.com/facebook/prepack/pull/1561
Closes https://github.com/facebook/prepack/pull/1555

Differential Revision: D7220598

Pulled By: trueadm

fbshipit-source-id: 2d0b87e23ecd93b325f44daa3a7c21ff3591d733
2018-03-10 07:13:00 -08:00
Dominic Gannaway
fb2786d433 Fixes a React first render issue with component instance
Summary:
Release notes: none

When rendering a class component on first render, we need to ensure it's instance is intrinsic otherwise it will serialize out incorrectly.
Closes https://github.com/facebook/prepack/pull/1556

Differential Revision: D7220974

Pulled By: trueadm

fbshipit-source-id: 968afb5b7dbfc6f7714862d9cbedf6e793c9e504
2018-03-09 16:54:49 -08:00
Dominic Gannaway
67f4c3e741 Various React fixes
Summary:
Release notes: none

Various fixes to get the UFI evaluating without invariants and other issues. Also added `componentsEvaluated` statistics.
Closes https://github.com/facebook/prepack/pull/1535

Differential Revision: D7172478

Pulled By: trueadm

fbshipit-source-id: 683a1039f22241261e7a5e216ec614b21ff57a92
2018-03-06 14:11:03 -08:00
Dominic Gannaway
4b9858f84b Allow simple object property access with an abstract dynamic key
Summary:
Release notes: Allow simple object computed property access with abstract property keys

The aim of this PR is to provide object computed property access when the property key is an abstract value and the object is a simple object. Furthermore, given the key is abstract, and converting it to a key might involve side-effects, this is only handled in a pure scope.
Closes https://github.com/facebook/prepack/pull/1530

Differential Revision: D7164200

Pulled By: trueadm

fbshipit-source-id: dfd8ac86985fd9d96fc18c6c28b954dff51eab27
2018-03-05 18:49:37 -08:00
Dominic Gannaway
079404fafc Adds firstRenderOnly mode
Summary:
Release notes: none

Adds a new React reconciler rendering mode called `firstRenderOnly`, activated by in the config passed to `__optimizeReactComponentTree`. Will add documentation to the wiki once this PR is ready to land.
Closes https://github.com/facebook/prepack/pull/1531

Differential Revision: D7164196

Pulled By: trueadm

fbshipit-source-id: 79cf99f7aad6b4ac9c9c7ea699dab0b266a24788
2018-03-05 18:49:37 -08:00
Dominic Gannaway
45f37fdadf Remove react-rest console.error noise
Summary:
Release notes: none

We spam the console when running `test-react` and many of the errors are not errors but just noise. Interestingly this also brought about one test that genuinely is failing but before was bringing up an invalid bail-out with `dynamic-props.js`. I'll fix that as a follow up as it's unrelated to this PRs goal.
Closes https://github.com/facebook/prepack/pull/1529

Differential Revision: D7149640

Pulled By: trueadm

fbshipit-source-id: e3268bc92c62726a5686b1acfcfff4128b69f6cd
2018-03-04 02:24:49 -08:00
Dominic Gannaway
2bb791e464 Allow complex React class components to fold into simple class components
Summary:
Release notes: none

This PR introduces a big clean up and re-design of some of the React reconciler code to allow for better folding capabilities. This PR enables complex React class components to be folded into functional/simple React components. This involves cloning the class component data structure and copying it on to the functional component.

Finally, any original properties of the functional component, for example `getTrials` or `defaultProps` are copied from the original back over the top to ensure the existing semantics remain (otherwise `getTrials` etc will be missing from the root component).

This PR is a fundamental stepping stone to allow us to better fold component trees and also tidies up some of the existing logic to make it easier to reason with and understand.
Closes https://github.com/facebook/prepack/pull/1428

Differential Revision: D7146514

Pulled By: trueadm

fbshipit-source-id: 3c0581b4beb341dac1d563a8ec9861afa1bb1708
2018-03-03 11:13:50 -08:00
Dominic Gannaway
90b78fd73e Add missing fb tests
Summary:
Release notes: none

This PR enables fb10.js and adds fb11.js from https://github.com/facebook/prepack/pull/1434, thus closing that PR.
Closes https://github.com/facebook/prepack/pull/1518

Differential Revision: D7131867

Pulled By: trueadm

fbshipit-source-id: ab168809da1e625dfa427addadc465e13b68787f
2018-03-01 17:08:38 -08:00
Dominic Gannaway
7725abdbce Handle React component render props
Summary:
Release notes: none

This PR is the work to get component render props working with the reconciler. We check if a render prop function is safe to use a new root for a component tree by scanning it's bindings using the leak ref traverser. If we find a binding that was created in the parent component, then it's not safe to make the render prop an additional function.
Closes https://github.com/facebook/prepack/pull/1478

Differential Revision: D7119766

Pulled By: trueadm

fbshipit-source-id: 8d286f1bc0ace009d2304643ba527b9932d2aa93
2018-02-28 22:12:07 -08:00
Dominic Gannaway
4b6077c5de Small tidy up of ReactElement logic
Summary:
Release notes: none

This PR cleans up the logic in how ReactElement properties are visited, moving them to the right place in the codebase. `react/utils/getProperty` also now properly deals with missing properties and throws an introspection error for getters/setters.
Closes https://github.com/facebook/prepack/pull/1507

Differential Revision: D7092708

Pulled By: trueadm

fbshipit-source-id: 4064a0cf48b633bd77012afb99e514ac5716e062
2018-02-26 17:30:53 -08:00
Dominic Gannaway
cdec5c1005 Support more unary expression cases in pure scope
Summary:
Release notes: none

Support was added for delete unary expression cases a few days ago. This PR ensures all the other unary expression cases are also handled now too. The abstract temporal logic has been extended to support cases where the BaseValue of a reference was a EnvironmentRecord (when you destructure an object, this occurs).
Closes https://github.com/facebook/prepack/pull/1495

Differential Revision: D7075821

Pulled By: trueadm

fbshipit-source-id: 4cbbdc62ba03be41298c12aa57ce16d8d1225b2d
2018-02-23 16:38:53 -08:00
Dominic Gannaway
67ee4078a7 Fixes named function bindings in additionalFunction scope
Summary:
Release notes: none

This PR fixes a bug where named functions' bindings were being marked as global inside additionalFunctions. This meant that they were incorrectly being assigned to the global.

Fixes https://github.com/facebook/prepack/pull/1432
Closes https://github.com/facebook/prepack/pull/1489

Differential Revision: D7059627

Pulled By: trueadm

fbshipit-source-id: 232753cf591e4cb3f566578e3fe3844c28829d49
2018-02-22 14:10:35 -08:00
Dominic Gannaway
273312ecd8 Improve the ReactElement logic for evaluation to improve folding cases
Summary:
Currently, there are too many cases where ReactElement evaluation bails out. This PR aims to solve many of those cases:

- [x] Ensure `props` have a deleted `key` and `ref`
- [x] Refactor JSX evaluation to properly handle and deal with JSX spreads
- [x] Ensure all react-tests run both transpiled and non-transpiled so the `React.createElement` route can be evaluated and tested
- [x] Refactor React.createElement mock to work like the JSX evaluator
- [x] Throw and error when we've detected cases where `key` and `ref` are abstract and not deleted or defined

Will do in a follow up PR once other PRs land:
- Ensure that we internally pass around `reactHint` in cases of `Object.assign`
Closes https://github.com/facebook/prepack/pull/1447

Differential Revision: D7049578

Pulled By: trueadm

fbshipit-source-id: 7f8330c8e4c47c5095b672f686cedc593852a6a8
2018-02-21 16:26:29 -08:00
Dan Abramov
bd432f6316 Make Object.assign() safe to use with simple partial sources
Summary:
Fixes https://github.com/facebook/prepack/issues/1462.

Supersedes my attempts in https://github.com/facebook/prepack/pull/1459, https://github.com/facebook/prepack/pull/1460, and https://github.com/facebook/prepack/pull/1468.
The git history reflects a lot of back-and-forth so it might make more sense to look at the final code.

There are two separate fixes here:

* If we have a partial simple source and then a normal source, we shouldn't attempt to `Set` any further keys after the first partial. Instead we should emit residual `Object.assign` calls. If we set the keys, we end up with a wrong key order (a key gets set earlier than it should have). Key order (AFAIK) isn't mandated by the spec but tends to be relied on in product code because all engines preserve it in the order of assignments.

* It is not safe to mutate either a partial source or the target (when some sources are partial) in Prepack land after the `Object.assign` call. This is because Prepack will serialize all those mutations (as the object final state) right into the residual `Object.assign` call. But this is wrong because they haven't happened yet.

The second issue is thorny. In many cases sources (and the target) don't get mutated later. So we'd like to keep supporting `Object.assign` with partials when we don't touch them later.

To solve it, I introduced new `obj.makeFinal()` and `obj.isFinalObject()` methods. If an object is marked as "final", we cannot make changes to it that would change its emitted form. This is a way for us to say "let's try to continue as far as we can, but if anything tries to touch it, fatal".

It doesn't mean the object is "frozen" (technically we didn't freeze it), but it means Prepack can't deal with further mutations to it because Prepack has already "used" its current snapshot and it would be unsafe to change it.

I'm not sure I'm checking `isFinalObject()` in all places where it's necessary. If there is a way to do this with stronger guarantees please let me know. I want to still highlight that this fixes multiple existing issues on master so it's a step in a safer duration, even though I'm wary that if the concept is not fully baked, it might give a false sense of security.

Here's how we're using this new infra. When we emit a residual `Object.assign()` call because some sources are partial (and simple), I mark all sources and the target as "final". So if they don't get mutated, everything is fine. If they get mutated later, we get a fatal when they do. In the future Prepack might support this better, but the fatal makes it clear which cases it currently doesn't handle (and would produce wrong output for).

There might also be other cases where making an object as "final" lets us continue further, although I don't know Prepack codebase well enough to tell for sure. So I'm hoping it is useful as a generic concept outside of the `Object.assign()` use case.

The pure mode is treated a bit differently. In the pure mode we can get away with "leaking" final values whenever we need to write to them. Then they're treated like any other "leaked" object.

I added regression tests for all existing cases I could find, both in pure and impure mode.
Closes https://github.com/facebook/prepack/pull/1469

Reviewed By: trueadm

Differential Revision: D7046641

Pulled By: gaearon

fbshipit-source-id: 472188eeabe28dcce36ab026ecbcbc4c8e83176b
2018-02-21 13:48:31 -08:00
Dominic Gannaway
c6bb827f2d Ensure React non-composite nested array children are flattened
Summary:
Release notes: none

This change properly implements non-composite children flattening. This fixes https://github.com/facebook/prepack/pull/1465 too.
Closes https://github.com/facebook/prepack/pull/1471

Differential Revision: D7029252

Pulled By: trueadm

fbshipit-source-id: a76330d53f0537b8101ac604eec339bc4c210150
2018-02-20 06:32:42 -08:00
Dan Abramov
de01669c5d Object.assign() preserves simplicity of its target
Summary:
Alternative to https://github.com/facebook/prepack/pull/1450, per the discussion there.
Closes https://github.com/facebook/prepack/pull/1456

Reviewed By: sebmarkbage

Differential Revision: D7014527

Pulled By: gaearon

fbshipit-source-id: 2bc5dfa8a1c330a3d6e75bb4db11af8dd1c847f0
2018-02-16 14:31:26 -08:00
Dominic Gannaway
4f22fbae83 Add Hacker News app test and PropTypes mock require
Summary:
Release notes: none

This only adds the test, it current fails if we try and process the React tree. The aim is to get the app working in follow up PRs.
Closes https://github.com/facebook/prepack/pull/1463

Differential Revision: D7009913

Pulled By: trueadm

fbshipit-source-id: c0a04367143ed22171e58af4568fcb276e2b2872
2018-02-16 08:10:04 -08:00
Dominic Gannaway
df43524fdb Properly handle React functional component argument names
Summary:
Release notes: none

Fixes https://github.com/facebook/prepack/pull/1430
Closes https://github.com/facebook/prepack/pull/1453

Reviewed By: gaearon

Differential Revision: D6999763

Pulled By: trueadm

fbshipit-source-id: 15c97da4e87b140ad83ab945f33140ec9e51838d
2018-02-16 05:59:04 -08:00
Dominic Gannaway
414cc67b93 Re-adds Flow parsing and stripping when option is enabled
Summary:
Release notes: adds option to parse and strip Flow annotations

In a [tweet I made at the end of last year](https://twitter.com/trueadm/status/944908776896978946) I linked to a REPL example that contained Flow type annotations. The example is now broken as we removed Flow type annotation parsing. :(

This PR adds this back behind the option `stripFlow` which is now enabled by default on the REPL and for React tests. I've also added a test to match the REPL for regression checking so this doesn't happen.
Closes https://github.com/facebook/prepack/pull/1439

Differential Revision: D6976663

Pulled By: trueadm

fbshipit-source-id: 47e28bc0986f1a1a252180f26200ce32314a4e5b
2018-02-13 08:48:24 -08:00
Dominic Gannaway
ebb3db401e Refine ReactRelay mocks and add a reactHints tracking WeakMap
Summary:
Release notes: none

This PR adds `reactHints` property to AbstractValue and refines the ReactRelay mocks. `reactHints` allow us to do more with the React reconciler, without having to bail-out on encountering ReactRelay containers. So we now create the containers with a NativeFunction that allows us to finely create the `AbstractObjectValue`s back with the hints attached.

Without this change, the reconciler is unable to understand how to deal with ReactRelay container wrapped components (as they're left as abstract). We want to the containers abstract though, but we want to able to continue to process all the components in the tree. The hints provides special casing for making this work.

Furthermore, I've added tests that now properly incorporate ReactRelay and a relevant stub for tests that don't need the runtime in tests.
Closes https://github.com/facebook/prepack/pull/1418

Differential Revision: D6948627

Pulled By: trueadm

fbshipit-source-id: a6fb3690d8d9b472322ae1a8752f5a71a0747b52
2018-02-09 05:10:11 -08:00
Dominic Gannaway
a0f5bef610 Adds React.Fragment support
Summary:
Release notes: none

This PR adds React.Fragment support and updates `react`/`react-dom` Jest test dependencies.
Closes https://github.com/facebook/prepack/pull/1413

Differential Revision: D6942227

Pulled By: trueadm

fbshipit-source-id: 8fd04e7956efac9694b30088b136d9c344bca00e
2018-02-08 15:20:52 -08:00
Dominic Gannaway
b6464cb570 Adds React compiler statistics tracking
Summary:
Release notes: none

This PR adds Jest snapshot testing for the React compiler's statistics, so we can determine if we regress or improve the amount of compiled React component trees/inline components.
Closes https://github.com/facebook/prepack/pull/1422

Reviewed By: gaearon

Differential Revision: D6938242

Pulled By: trueadm

fbshipit-source-id: 1ebb192fd816d8f1b9b130818d283d270f698b78
2018-02-08 11:30:34 -08:00
Dominic Gannaway
e0bb001a83 Fix class visiting/serialization with inheritance chains
Summary:
Release notes: none

This PR fixes bugs in visiting and serializing the prototype. I've also added the test that this fails with before. I moved much of the duplicated logic from before that was the cause of this into a single function `getObjectPrototypeMetadata()`.
Closes https://github.com/facebook/prepack/pull/1407

Differential Revision: D6924282

Pulled By: trueadm

fbshipit-source-id: 67d6772a0207631acd3e30d142a95951fef6b374
2018-02-07 11:38:28 -08:00
Dominic Gannaway
e82ea63ea5 Handles more argument cases for FB global functions
Summary:
Release notes: none

Applied a better way for building FB abstract global functions where we might take arguments that are more complex than strings.

Fixes https://github.com/facebook/prepack/issues/1401
Closes https://github.com/facebook/prepack/pull/1402

Reviewed By: gaearon

Differential Revision: D6901108

Pulled By: trueadm

fbshipit-source-id: a3be0877763094c7974d5e41464d4c27c079c0db
2018-02-05 14:23:59 -08:00
Dominic Gannaway
6ff0d9f0c3 Add support for React factory class components
Summary:
Release notes: none

This PR adds support for the uncommon React factory component pattern – which is used by ReactRelay. I've also added a test.
Closes https://github.com/facebook/prepack/pull/1397

Differential Revision: D6890491

Pulled By: trueadm

fbshipit-source-id: 7d0434e6872f5ab3e171dbffae0bf877fae62c48
2018-02-02 17:55:11 -08:00
Dominic Gannaway
12d7215def Better handling of fb-www require, cx and Bootloader
Summary:
Release notes: none

These are mainly targeted at internal fixes to require calls we need.

- Fixes the `require` system so that it returns the same abstract function for the same call. We now memoize values on a `Map` on `realm.fbLibraries.other`
- Adds two new FB internal globals `cx` and `Bootloader`
- To prevent extra serialization bloat, kind = "resolved" is used on some objects.
Closes https://github.com/facebook/prepack/pull/1392

Differential Revision: D6883197

Pulled By: trueadm

fbshipit-source-id: 6833d2a88c44d72aa9a35172cad6ba88c013cd11
2018-02-02 05:08:10 -08:00
Dominic Gannaway
661271cc76 Fixes issues handling array leakage logic
Summary:
This PR fixes some of the bugs we found in the leak logic:

- handling of arrays added
- adds `evaluateWithoutLeakLogic()` to Realm
- test case added

Depends on: https://github.com/facebook/prepack/pull/1383
Closes https://github.com/facebook/prepack/pull/1382

Reviewed By: gaearon

Differential Revision: D6858693

Pulled By: trueadm

fbshipit-source-id: 0b2272cd669898a71a4566b8f99019026884e289
2018-01-31 11:54:26 -08:00