Commit Graph

12 Commits

Author SHA1 Message Date
Robert Zhang 2c37aa78d3 [Playground] Style compiler options editor
This diff adds styling to the compiler options editor. The floating input/output 
toggle button on small screens now spans the bottom of the screen, so that it 
doesn't block the compiler options. 

Height overflows when adjusting screen size are complicated by Monaco Editor and 
will be addressed in a later diff. 

Test plan: 

Start Playground and see the latest look of the compiler options editor beneath 
the output section.
2022-10-23 18:33:39 -04:00
Joseph Savona 515c33d2a6 Custom version of no-use-before-define rule
## Proper Detection of Out-of-order Functions 

The no-use-before-define rule from ESLint has a strange behavior in which it 
treats variables differently than functions: 

```javascript 

function foo() { 

return bar(X); 

} 

const X = null; 

function bar(x) {} 

``` 

By default, `bar(x)` has two errors: one because X is used before defined, and 
once because `bar` is used before defined. The rule has an option `{variables: 
false}` which only enables validation when the variable is from the same "scope" 
as the reference, the net result of which is it means it doesn't report spurious 
errors such as X being undefined. There is _also_ a `{functions: false}` option, 
but for some reason that doesn't work the same way, it just turns off all 
validation of references that came from functions. So enabling that option would 
suppress the (spurious) error on invoking `bar()` above, but causes the rule to 
miss invalid code such as: 

``` 

function foo() { 

return bar(); 

function bar() {} 

} 

``` 

This PR adds a fork of the rule that makes `{functions: false}` behave similarly 
to `{variables: false}`, which should help avoid some of the spurious errors i 
saw internally. The rule is exported from Forget itself, which will make it 
easier to consume internally, in tests, and in the playground. 

## Targeting the validation to Forget functions 

Even with the above, there are still some false positives coming from code such 
as: 

```javascript 

const x = foo(); 

function foo() {} 

``` 

This PR changes codegen to ensure that the output of a function _always_ has the 
body starting with 'use forget'. The ESLint rule then only looks at function 
declarations/expressions whose body starts with that expression. The new unit 
test confirms that the validation finds invalid reorderings even on functions 
that weren't explicitly tagged as 'use forget'.
2022-10-27 16:29:09 -07:00
Joseph Savona f4df345420 Improve playground validation, workaround lack of JSX support
ESLint's default parser doesn't support any non-standard syntax, which includes 
JSX. So when I added the ESLint validation step to the playground, it meant that 
valid examples containing JSX still reported "invalid output". I tried to use an 
alternative parser, but I couldn't figure out the right webpack incantations to 
make `@babel/eslint-parser` or `hermes-eslint` work. I even tried recreating 
some of their code to avoid problematic imports, no dice. 

Instead this PR: 

* No longer uses the `postCodegenValidator` step, and runs the validation on the 
output after compilation completes. This is better anyway since we can see the 
output *and* the error messages 

* Shows rule violations as an "Invalid output" comment 

* Shows parser errors as a note (mostly to indicate that the validation step 
couldn't run, there could still be no-use-before-define violations that weren't 
found) 

Invalid example: 

<img width="1502" alt="Screen Shot 2022-10-21 at 9 50 23 AM" 
src="https://user-images.githubusercontent.com/6425824/197249007-1ec244a0-6dfe-4ec6-a0d0-60302efd86bd.png"> 

Sample example but with some JSX: 

<img width="1500" alt="Screen Shot 2022-10-21 at 9 50 39 AM" 
src="https://user-images.githubusercontent.com/6425824/197249030-e68ba968-4101-47c7-a148-f548f84f375c.png">
2022-10-21 11:00:39 -07:00
Joseph Savona 2f34f85011 Enable no-use-before-define validation in playground
#686 added an option to validate generated code after transformation and adds an 
ESLint-based validator function to transform-test. Unfortunately it isn't super 
easy to wire up ESLint for use in a browser: traditionally the ESLint project 
specifically did _not_ support browser builds, but they recently have relaxed 
this because they added a browser playground on their website. There isn't 
official support, but the [playground 
repo](https://github.com/eslint/playground/blob/f3b1f78cc1c06dadfe7bb50c6c0f913c0d23670d/webpack.config.js) 
has a webpack config that, when combined with requiring a specific file, allows 
making things work in a browser. 

I tried using this directly in our playground app but Next's default webpack 
config doesn't work. So I created a separate package, playground-validator, 
which exports a webpack-built version of `eslint.Linter`. Then the playground 
can consume that, and everything works: 

## Test Plan 👀 

Confirmed that a known problematic example displays the validation message in 
playground (both locally and on the preview deployment): 

<img width="1500" alt="Screen Shot 2022-10-20 at 12 22 59 PM" 
src="https://user-images.githubusercontent.com/6425824/197041265-966ffda2-a3d0-450e-8fc4-fd1a7ca06e1a.png">
2022-10-21 08:37:18 -07:00
Lauren Tan 46d7f4f8af Synchronize symbol names with React
In the upstream useMemoCache PR this symbol got renamed and unexpectedly caused 
a RN crash. Synchronize it so the comparison works.
2022-10-17 16:07:50 -04:00
Lauren Tan b03752cbe0 Use for loop instead of Array.prototype.fill
Some prior [microbenchmarking](https://jsbench.me/7ol98ws520/1) showed that a 
for loop outperformed `fill` (which is about ~60% slower). This is the same 
approach we use in the latest useMemoCache PR
2022-10-17 16:07:50 -04:00
Jan Kassens 90e189ae82 Add react-forget-runtime
This is a new module that holds: 

- the `useMemoCache` stub (hopefully to be deleted next week) 

- various helpers that can be imported by the compiler, e.g. the dispatcher 
guard `$startLazy` 

- skipped the implementation of `makeReadOnly` for now as there's already 
multiple copies and I wanted to avoid typescript in this file for now to make 
the build easier (i.e. no build)
2022-10-17 13:08:34 -04:00
mofeiZ 73059d9a4f [Playground][Nit] Add delete + overtype for autoclosing brackets
Fix for papercut: playground should now be smart about autoclosing brackets. 

Before: 


https://user-images.githubusercontent.com/34200447/195653419-0eb529e4-0aed-4894-9db6-bfe1554aaded.mov 

Now: 


https://user-images.githubusercontent.com/34200447/195653738-07abed36-d9e8-4842-bac5-9e84b72c0704.mov
2022-10-13 13:16:56 -04:00
Jan Kassens 7f17dd84d1 Import useMemoCache from unstable name
I didn't make this an option as it's unclear we'll really need this. We can 
always add an option later, I think. 

This is the name that's available on facebook.com at the moment.
2022-10-11 13:16:01 -04:00
Mofei Zhang 896ef251b4 patch makeReadOnly into playground 2022-10-03 14:37:24 -04:00
Mofei Zhang 72775fba10 makeReadOnly implementation
Added utility package to track mutations to objects marked as "read-only".
2022-09-29 14:17:38 -04:00
Xuan Huang (黄玄) a33c0b897c Initial commit 2024-03-25 10:39:47 +00:00