Skip to content

Commit

Permalink
[compiler][ez] Enable some sprout tests that no longer need to be dis…
Browse files Browse the repository at this point in the history
…abled

Summary:
As title. Better support for flow typing, bugfixes, etc fixes these

ghstack-source-id: 6326653ce42b33b6c1c76a494434d133382ca80a
Pull Request resolved: #30591
  • Loading branch information
mvitousek committed Aug 12, 2024
1 parent 6532c41 commit 0d7c12c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ export default component Foo(bar: number) {
return <Bar bar={bar} />;
}

component Bar(bar: number) {
return <div>{bar}</div>;
}

function shouldNotCompile() {}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{bar: 42}],
};

```

## Code
Expand All @@ -29,7 +38,28 @@ export default function Foo(t0) {
return t1;
}

function Bar(t0) {
const $ = _c(2);
const { bar } = t0;
let t1;
if ($[0] !== bar) {
t1 = <div>{bar}</div>;
$[0] = bar;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
}

function shouldNotCompile() {}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{ bar: 42 }],
};

```
### Eval output
(kind: ok) <div>42</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ export default component Foo(bar: number) {
return <Bar bar={bar} />;
}

component Bar(bar: number) {
return <div>{bar}</div>;
}

function shouldNotCompile() {}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{bar: 42}],
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export default hook useFoo(bar: number) {
return [bar];
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [42],
};

```

## Code
Expand All @@ -26,5 +31,12 @@ export default function useFoo(bar) {
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [42],
};

```
### Eval output
(kind: ok) [42]
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
export default hook useFoo(bar: number) {
return [bar];
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [42],
};
8 changes: 4 additions & 4 deletions compiler/packages/snap/src/SproutTodoFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,12 @@ const skipFilter = new Set([
'template-literal',
'multi-arrow-expr-export-default-gating-test',

// TODO: we should be able to support these
'component-declaration-basic.flow',
'hook-declaration-basic.flow',
// works, but appears differently when printing
// due to optional function argument
'nested-function-with-param-as-captured-dep',
'deeply-nested-function-expressions-with-params',

// TODO: we should be able to support these
'readonly-object-method-calls',
'readonly-object-method-calls-mutable-lambda',
'preserve-memo-validation/useMemo-with-refs.flow',
Expand Down Expand Up @@ -483,7 +484,6 @@ const skipFilter = new Set([
'rules-of-hooks/rules-of-hooks-69521d94fa03',

// bugs
'bug-renaming-jsx-tag-lowercase',
'fbt/bug-fbt-plural-multiple-function-calls',
'fbt/bug-fbt-plural-multiple-mixed-call-tag',
'bug-invalid-hoisting-functionexpr',
Expand Down

1 comment on commit 0d7c12c

@waqas12321
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on refactoring the Foo and Bar components! The use of caching with the $ array in the Bar function is a clever optimization to avoid unnecessary re-renders. However, it might be helpful to add a brief comment explaining the purpose of the $ array for maintainability, especially for those who might be unfamiliar with this approach. Also, ensuring consistency in naming conventions could improve readability—for instance, keeping variable names like t0 and t1 more descriptive. Overall, the changes look solid and should enhance performance. Kudos!

Please sign in to comment.