Commit Graph

70 Commits

Author SHA1 Message Date
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
Herman Venter
4944f2e939 Fix flow errors
Summary:
Update Flow and fix errors found by new version.

I'm none to sure the changes to the code are desirable. Perhaps the flow types for babel-types need to be updated?
Closes https://github.com/facebook/prepack/pull/1127

Differential Revision: D6222475

Pulled By: hermanventer

fbshipit-source-id: 208b89787914fc7d1e322cb14a6ff2374cd24b9a
2017-11-03 00:10:03 -07:00
Dominic Gannaway
e63daa5585 Add React/Jest testing infrastructure
Summary:
Release note: none

This PR adds the React/Jest testing infrastructure to Prepack and is stacked on the PR https://github.com/facebook/prepack/pull/1117. Thus, that PR should be merged before this PR is merged to reduce noise in the diff.

This will allow us to test various runtime outputs of React 16 when running original source vs Prepacked source to see if there are any issues/differences that might have an impact on applications. The primary reason for this is to track regressions for the component folding PRs that will land in the future.

Please note, this PR does not contain any reconciler changes, thus `__registerReactComponentRoot(App);` has been commented out of tests to ensure they don't prematurely fail. A follow up PR will enable them once the other React functional component folding PRs get landed.

This PR also adds some mock React globals to be used within tests (and maybe to be further integrated into folding at a future point too). The mocks include `React.Component` and `React.cloneElement` for now.

Furthermore, a `utils/json.js` utility file exists to help normalize the results from the React test renderer so that adjacent JSON text nodes get merged, which is something that may exist because of how the reconciler (once the PR lands) handles inlining of child nodes.

The command to run React tests is `yarn test-react`.
Closes https://github.com/facebook/prepack/pull/1118

Reviewed By: cblappert

Differential Revision: D6208263

Pulled By: trueadm

fbshipit-source-id: d54f3b0e1cc3240e1f142d3da08bc279e4153889
2017-11-02 04:40:33 -07:00
Wuhan Zhou
f6279bd814 Framework for debug adapter and mock ui
Summary:
Release note: none
Issue: #907

- Mock UI as a CLI to communicate with the adapter
- Starter code for the debugger adapter with an initialize request
Closes https://github.com/facebook/prepack/pull/1088

Differential Revision: D6108024

Pulled By: JWZ2018

fbshipit-source-id: 506ec039dcb1ff540872cb2e1a87a165cfd22e4d
2017-10-20 11:08:33 -07:00
Chris Blappert
37fa45bf12 New code coverage step
Summary: Adds new `test-coverage-all` command to `package.json` which will run and compose all test coverage information into one html.

Reviewed By: hermanventer

Differential Revision: D6052366

fbshipit-source-id: 208259fa79185267f6c7a51ca8baf08ffb707e97
2017-10-19 17:58:26 -07:00
Herman Venter
8cf13339ab New alpha version
Summary: Bump version number for new alpha

Reviewed By: cblappert

Differential Revision: D6079917

fbshipit-source-id: b7f640001a830813a1b2343efc4ccfeac9810679
2017-10-18 01:01:54 -07:00
Herman Venter
a89b3b2a4d Weekly release v0.2.10: Exceptions, JSX, optimizations
Summary:
Release notes:
Generate code for uncaught exceptions at the top level
Adds JSX and ReactElement evaluation/serialization support
Avoid duplicate nested function bodies

Reviewed By: cblappert

Differential Revision: D6079861

fbshipit-source-id: e80e813469def0b98b1799edb79217f45980f911
2017-10-18 01:01:54 -07:00
Dominic Gannaway
cfc6993e9c Basic JSX/ReactElement support
Summary:
Release notes: adds JSX and ReactElement evaluation/serialization support

This adds JSX/ReactElement support to the Prepack serializer so `ReactElement` "like" objects can correctly be converted back to JSX syntax. Example:

```jsx
'use strict';

const externalThing = __abstract('function', 'externalThing');

function Test() {
  return <div>{ externalThing() }</div>
}

global.test = Test;
```

Becomes:
```jsx
'use strict';

var _$0 = this;

var _0 = function () {
  return <div>{_1()}</div>;
};

var _1 = externalThing;
_$0.test = _0;
```

I've also added a JSXElement -> ReactElement evaluator.
Closes https://github.com/facebook/prepack/pull/1051

Differential Revision: D6053275

Pulled By: trueadm

fbshipit-source-id: 7c31545751ceedba55cdd4581bc6de51a98b412a
2017-10-13 12:18:35 -07:00
Chris Blappert
bc232a5987 New alpha version for prepack
Summary: New alpha version v0.2.10

Reviewed By: hermanventer

Differential Revision: D6024238

fbshipit-source-id: b6a0492e431910185ab11f3ea9474b41c883138e
2017-10-10 15:35:16 -07:00
Chris Blappert
5878e34eb6 Prepack Weekly Release v0.2.9: optimizations, abstract conditional enhancements
Summary:
Bump version for new release:
1. Enhance Additional Functions testing and functionality.
2. Enhance factorifyObjects() for delay initializations code block.
3. Fix a bug that Prepack may generate invalid syntax for abstract model with special characters in binding name.
4. Support exceptions that are thrown, inside a try-catch, based on an abstract condition.
5. Allow Map, Set, WeakMap and WeakSet to be used inside branches of abstract conditionals.
6. Allow use of arguments.caller property in non strict mode.

Reviewed By: hermanventer

Differential Revision: D6024226

fbshipit-source-id: 99cfcbe6071d4d5820edd8ba838c209586f4fa71
2017-10-10 15:35:16 -07:00
Jeffrey Tan
512dcc4fb6 Update to new alpha version 0.2.9
Reviewed By: cblappert

Differential Revision: D5966141

fbshipit-source-id: 967633f97bfe6b3746df9d714fec0e76ce6c33e2
2017-10-03 15:09:35 -07:00
Jeffrey Tan
736f9115ca Weekly release v0.2.8: better diagnostics and condition simplifications
Summary:
Major commits include:
* Change error message when evaluating PossiblyNormalCompletion
* Added --omitInvariants option to prevent invariants from being included in generated code.
* Print out call stack in default error handler
* More simplifications
* Add missing check for invalid use of Map
* Simplify if conditions

Reviewed By: cblappert

Differential Revision: D5965959

fbshipit-source-id: e8eb8e053d9a121d2b4de352658269a5ec856f43
2017-10-03 15:09:34 -07:00
Herman Venter
19251e4e74 New Alpha version 0.2.8
Summary: New alpha after version bump

Reviewed By: yinghuitan

Differential Revision: D5913655

fbshipit-source-id: 9207bc43896b0688b17d6042b3330477d7e538b7
2017-09-26 15:40:46 -07:00
Herman Venter
8143d6d181 Weekly release v0.2.7: Refinement and simplification
Summary: Basic expression simplification and refinement with path conditions. Various small improvements.

Reviewed By: yinghuitan

Differential Revision: D5913534

fbshipit-source-id: efb259347d5300abae0ce50d0267134aaeeab853
2017-09-26 15:40:46 -07:00
Chris Blappert
cd3821ab7e Serialize independent functions
Summary:
Currently works for all test cases except `noconflict-existantobject.js`.

There are a couple things that are dubious in the current implementation that I will address as I iterate on it:
* We don't visit things correctly in the visitor or the serializer -- we should be visiting only:
  * generator entries in effects
  * Bindings, PropertyBindings in effects not relating to CreatedObjects
* There is currently no way to emit to the main body after the main generator has been serialized -- we may need to if a value is only reachable from one of the additional functions.
* More thought needs to go into how this interacts with
  * speculative initialization
  * require optimization
  * inlining
Closes https://github.com/facebook/prepack/pull/912

Differential Revision: D5859741

Pulled By: cblappert

fbshipit-source-id: 9fe7bd4429ad53629582f9fb7154a28971159554
2017-09-25 16:53:45 -07:00
chico
1edb96ade2 Update Flow to 0.54.0
Summary:
Closes #905

Error mentioned in issue above was fixed in d145b375ed
Closes https://github.com/facebook/prepack/pull/947

Differential Revision: D5812790

Pulled By: yinghuitan

fbshipit-source-id: 00779dd18a334d6b15cacf8d98b05b780e6844ee
2017-09-11 22:54:02 -07:00
Herman Venter
f8a7f8dada Make it easier to combine abstract values via operators. Part 1.
Summary:
In this part, the code for creating an abstract value that results from a binary operator is centralized into AbstractValue.createFromBinaryOp. As part of this, TypeDomain and ValuesDomain now have transfer functions for computing the domain values that result from binary operations.

If this pattern is acceptable, I'll extend it to the other operators.
Closes https://github.com/facebook/prepack/pull/937

Differential Revision: D5734009

Pulled By: hermanventer

fbshipit-source-id: 0e775116b86df5de5da805de241436ecdc575605
2017-08-29 20:59:05 -07:00
Andres Suarez
69f5d05ebc Upgrade to babylon@6.18.0
Summary: babylon@6.18.0 has support for "opaque type alias" syntax (https://github.com/babel/babylon/releases/tag/v6.18.0 and https://medium.com/flow-type/hiding-implementation-details-with-flows-new-opaque-type-aliases-feature-40e188c2a3f9).

Reviewed By: cblappert

Differential Revision: D5706930

fbshipit-source-id: 8cdaee77b838812ebb012a352f7e77b74838b536
2017-08-29 16:26:03 -07:00
Chris Blappert
455d43cbaf New alpha version
Summary: New alpha after version bump

Reviewed By: hermanventer

Differential Revision: D5673084

fbshipit-source-id: c11532139841988e036a71470c7443ea3fc1a91e
2017-08-21 18:23:06 -07:00
Chris Blappert
30742e6f6e New Prepack Version
Summary: Reworks API, better debuggability and some bugfixes

Reviewed By: NTillmann

Differential Revision: D5672973

fbshipit-source-id: 0e0ce2d199b4fa0cb1ee17acfa5078bdedeb2242
2017-08-21 18:23:06 -07:00
Herman Venter
50ce236f5e Catch fatal errors in visitName.
Summary:
Introspection errors no longer show up as completions, so any time we evaluate a node that might cause an introspection error, we should expect to catch and handle a FatalError.

Also tweaked package.json to allow longer stack traces when running test-serializer and tweaked test-internal to output error messages that do not have associated source locations. (The latter should not happen in practice but could happen when things go wrong.)
Closes https://github.com/facebook/prepack/pull/866

Differential Revision: D5563965

Pulled By: hermanventer

fbshipit-source-id: e2a74ec19314703526ebd35f7b8e694c19d82ab0
2017-08-04 11:20:16 -07:00
Herman Venter
57977cd361 Downgrade errors to warnings when speculatively prepacking modules
Summary:
There were two instances of the pattern and the second contained an omission that broke it. Factored out the pattern and made sure it works in both cases now.
Closes https://github.com/facebook/prepack/pull/851

Differential Revision: D5523645

Pulled By: hermanventer

fbshipit-source-id: 086cf9aadb1e31279ae11b512f367daddf726d55
2017-07-28 19:38:40 -07:00
Chris Blappert
3b35ad6996 Temporary fix for module tracer by disabling rewrite
Summary:
Added regression test and re-enabled resolve initialized modules.

Also, fixed bug in cli.
Closes https://github.com/facebook/prepack/pull/829

Differential Revision: D5499240

Pulled By: cblappert

fbshipit-source-id: 012766ea652e60d2de2822894b41610542a3a2eb
2017-07-27 11:00:10 -07:00
Herman Venter
f8bf43f673 Update yarn.lock
Summary:
Update Babylon and adjust expected pass count to match what I see on my laptop.

The difference was due to my version of Babylon (which is the latest for some or other reason I don't understand) giving a syntax error that did not occur with the version on the CI machine. Updating the yarn lock file gets the CI machine in sync with my laptop with respect to those tests.

Note that some String.prototype tests only pass with recent versions of Node.
Closes https://github.com/facebook/prepack/pull/831

Differential Revision: D5489742

Pulled By: hermanventer

fbshipit-source-id: 5732e47718c53d9f20de04fd64c1389524f33309
2017-07-25 14:27:51 -07:00
Nikolai Tillmann
649834eae9 @allow-large-files [prepack][PR] Updating Flow, and removing no longer needed suppression.
Summary: Closes https://github.com/facebook/prepack/pull/827

Differential Revision: D5484313

Pulled By: NTillmann

fbshipit-source-id: 7832fc792d8964735fb598e09389fb48e495d541
2017-07-24 18:26:49 -07:00
Jeffrey Tan
3c0b057e1a Enable eslint prettier plugin
Summary:
After adding this plugin, you just need to install https://github.com/AtomLinter/linter-eslint Atom package to surface ESLint errors(including prettier errors) in Nuclide linter UI. You also got auto-fix support in the Nuclide UI. Similarly, in VSCode, you can install https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint plugin to surface ESLint error in VSCode UI.
One caveat is that, eslint-plugin-prettier uses its own version of prettier(1.3.1) which may diverge from what we want. If we really found a file that diverge in formatting, we may have to add it into .eslintignore to ignore from UI/linter.
Closes https://github.com/facebook/prepack/pull/816

Differential Revision: D5444642

Pulled By: yinghuitan

fbshipit-source-id: 1670129d62e5e799a50c53d78387b5ded4c2c964
2017-07-18 14:09:05 -07:00
Jeffrey Tan
7612bb6084 Enable source map for scripts
Summary:
Enables source map for scripts folder so that we can debug test runners.
Closes https://github.com/facebook/prepack/pull/819

Differential Revision: D5444607

Pulled By: yinghuitan

fbshipit-source-id: ac80516dfb9f91e469cfc2d4a0c8c3108f78d83e
2017-07-18 11:45:54 -07:00
Herman Venter
ac7daf654b Error messages for for of loops
Summary:
Report errors rather than throw IntrospectionErrors. Added test cases to get 100% coverage of ForOfStatement.js. Fixed a few bug that came to light because of the new tests.
Closes https://github.com/facebook/prepack/pull/803

Differential Revision: D5411294

Pulled By: hermanventer

fbshipit-source-id: 818a5fb4c8112fc33c8531602eee5c0f6ecf25cb
2017-07-12 17:10:26 -07:00
Nikolai Tillmann
164c0eb9c3 Giving choice - npm or yarn.
Summary:
Fixing issue raised in #782.
Closes https://github.com/facebook/prepack/pull/786

Differential Revision: D5394680

Pulled By: NTillmann

fbshipit-source-id: b1f9f42425e759b68fbce5aa77f6d5a02e162756
2017-07-10 17:39:12 -07:00
Chris Blappert
cf19fb17af New alpha version
Summary: bump to new alpha version after npm release

Reviewed By: hermanventer, NTillmann

Differential Revision: D5394775

fbshipit-source-id: 24d09f8240b552d5deeb63c0dcf9341193692a8f
2017-07-10 17:31:09 -07:00
Chris Blappert
9001ce4c52 Weekly release v0.2.5: classes, better errors, API rework
Summary: prepack version bump for npm release

Reviewed By: hermanventer, NTillmann

Differential Revision: D5394759

fbshipit-source-id: 98de653466534ddc8e85bcf285d60a1fdf709088
2017-07-10 17:31:09 -07:00
wdhorton
7f5ec3b43f Making Prettier a check-in gate
Summary:
This supersedes #760.

Additional changes over #760:
Pinning Prettier version to get some formatting always. (Different prettier versions were responsible for the observed flip-flopping of StringPrototype.js.)
Print output of prettier in wrapper script for better diagnosis / experience. (TODO: How to just pipe through console output? Couldn't get it to work.)
Updating problematic .js file for the last time.
Closes https://github.com/facebook/prepack/pull/787

Differential Revision: D5382336

Pulled By: NTillmann

fbshipit-source-id: 95ed988ef3f091493d2fb509b5481753d56901cd
2017-07-07 11:35:32 -07:00
Sangboak Lee
1c23533c39 Change processSerializedCode func to receive error as 1st arg
Summary:
Since example code of [How to run Prepack](https://github.com/facebook/prepack#how-to-run-prepack) doesn't work(https://github.com/facebook/prepack/issues/781 )
I fixed `processSerializedCode` function to handle error as 1st argument
which follows 'error first callback' convention.
And to verify the changes I've added test code for the case of `StdIn`
Closes https://github.com/facebook/prepack/pull/784

Differential Revision: D5375275

Pulled By: NTillmann

fbshipit-source-id: ea85d0f30db4305aa7fcb5b69bf28f5998a84962
2017-07-06 12:39:48 -07:00
wdhorton
f909b69a74 Enable Prettier and remove conflicting eslint rules.
Summary:
Per discussion in #729, this sets up prettier but doesn't actually run it on the codebase.
Closes https://github.com/facebook/prepack/pull/759

Reviewed By: Kishore-B-Rao

Differential Revision: D5343135

Pulled By: NTillmann

fbshipit-source-id: 638740d48b6fa797fa79b8b5fd3c032497cb0132
2017-06-29 12:23:49 -07:00
Chris Blappert
675633782b New alpha version
Summary: after release, bump version number to new alpha for prepack

Reviewed By: NTillmann

Differential Revision: D5292338

fbshipit-source-id: 09248f7193e2dd58c8584a1cb9a23d636f2ba67f
2017-06-21 08:23:07 -07:00
Chris Blappert
bc8651356f Weekly release v0.2.4: node8, bugfixes, new optimization
Summary: Change version number, yarn.lock in preparation of publishing new npm package

Reviewed By: NTillmann

Differential Revision: D5292317

fbshipit-source-id: d91edcbdbbcfe9a0e7ad2530700899e3ef3cfb60
2017-06-21 08:23:07 -07:00
Herman Venter
5ab094db60 More error messages for binary ops
Summary:
Add message for < > >= <= != ==

Also run more tests with code coverage.
Closes https://github.com/facebook/prepack/pull/728

Differential Revision: D5280091

Pulled By: hermanventer

fbshipit-source-id: b6e96451940cecde4bd8e494b4fe55a93c78e984
2017-06-19 17:09:05 -07:00
Kishore-B-Rao
69a0df7e54 Merge pull request #722 from facebook/easierTesting
Easier testing
2017-06-12 17:25:49 -07:00
Christopher Blappert
04e4263d21 Bump node version (#721) 2017-06-12 14:36:56 -07:00
Kishore B. Rao
3835957329 Update circle to deal with the fact that the test scripts are now es6. I have also updated the package.json with a build-scripts rule that transpiles the test cases. As a local developer you can now run watch to transpile test scripts as well as source code 2017-06-12 14:32:32 -07:00
Kishore B. Rao
9620d60117 New serializer tester is es6 so the the build rules in the package.json file have been updated to accomodate this change 2017-06-12 12:17:21 -07:00
Guy Hershenbaum
7d7f07b436 Enable compiler-diagnostics reporting for errors (#698)
Added interface for reporting compilation/evaluation errors with relevant metadata
The new interface is used in a single location as a proof-of-concept

* Cleaning up the interface for handling recoverable errors

* more general recoverable error

* Addressed review comments

* Addressed review comments + added basic tests

* Address review comments #2

* Addressed CR comment about errorHandler in Options

* Fixing typo in import

* Address more review comments

* Fix linter errors

* Fix more linter errors

* Adjust test runners to run the new test
2017-06-06 15:53:39 -07:00
Herman Venter
1ae3427a27 Partial evaluator for if statement (#700) 2017-06-05 13:57:38 -07:00
Herman Venter
4ac76366e9 Partial evaluator for assignments (#692)
* First draft for partial evaluators

* Simple binary operator cases

* Track I/O statements separately

* Partial evaluator for assignments
2017-06-01 19:25:09 -07:00
Chris Blappert
4914101e6d Bump to new alpha 2017-05-31 17:24:38 -07:00
Chris Blappert
25dee4e5a6 Bump version for weekly release v0.2.3 2017-05-31 17:19:11 -07:00
Herman Venter
c4062bf477 Update Flow version, fix new Flow errors (#678) 2017-05-26 14:52:45 -07:00
Henry Zhu
923dea7aa3 Use preset-env (#512) 2017-05-23 17:30:54 -04:00
Sebastian Markbåge
a947b06290 Leave a residual function in prepack-cli (#655)
This lets us prepack Prepack itself using the node-cli option. Added a
yarn shortcut to run it with the required flags.

Just for fun.
2017-05-23 07:24:00 -07:00
Herman Venter
5324826a42 Add yet another test to time out list. (#665) 2017-05-22 11:52:41 -07:00