mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
[repro] Repro for fbt preserve whitespace bug
Current sprout output (if you remove the line in `SproutTodoFilter`):
```
Failures:
FAIL: bug-fbt-preserve-whitespace
Difference in forget and non-forget results.
Expected result: {
"kind": "ok",
"value": "Before text hello world",
"logs": []
}
Found: {
"kind": "ok",
"value": "Before texthello world",
"logs": []
}
```
`fbt` transforms run before jsx ones, so our lowering should also account for
[fbt's whitespace
rules](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtImplicitParamNode.js#L230-L233)
in `BuildHIR:trimJsxText`.
This commit is contained in:
1 parent
59ddf537ed
commit
6c327b0f3e
5 files changed
+188
No files matched your search
+65
@@ -0,0 +1,65 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import fbt from "fbt";
|
||||
/**
|
||||
* TODO: remove this from SproutTodoFilter when fixed.
|
||||
*/
|
||||
|
||||
function Component({ value }: { value: string }) {
|
||||
return (
|
||||
<fbt desc="descdesc">
|
||||
Before text
|
||||
<fbt:param name="paramName">{value}</fbt:param>
|
||||
</fbt>
|
||||
);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "hello world" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import fbt from "fbt";
|
||||
/**
|
||||
* TODO: remove this from SproutTodoFilter when fixed.
|
||||
*/
|
||||
|
||||
function Component(t11) {
|
||||
const $ = useMemoCache(2);
|
||||
const { value } = t11;
|
||||
let t0;
|
||||
if ($[0] !== value) {
|
||||
t0 = fbt._(
|
||||
"Before text{paramName}",
|
||||
[
|
||||
fbt._param(
|
||||
"paramName",
|
||||
|
||||
value
|
||||
),
|
||||
],
|
||||
{ hk: "3DIRxJ" }
|
||||
);
|
||||
$[0] = value;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "hello world" }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import fbt from "fbt";
|
||||
/**
|
||||
* TODO: remove this from SproutTodoFilter when fixed.
|
||||
*/
|
||||
|
||||
function Component({ value }: { value: string }) {
|
||||
return (
|
||||
<fbt desc="descdesc">
|
||||
Before text
|
||||
<fbt:param name="paramName">{value}</fbt:param>
|
||||
</fbt>
|
||||
);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ value: "hello world" }],
|
||||
};
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { StaticText1 } from "shared-runtime";
|
||||
|
||||
function Component() {
|
||||
return (
|
||||
<div>
|
||||
Before text
|
||||
<StaticText1 />
|
||||
Middle text
|
||||
<StaticText1>
|
||||
Inner before text
|
||||
<StaticText1 />
|
||||
Inner middle text
|
||||
<StaticText1 />
|
||||
Inner after text
|
||||
</StaticText1>
|
||||
After text
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { StaticText1 } from "shared-runtime";
|
||||
|
||||
function Component() {
|
||||
const $ = useMemoCache(3);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <StaticText1 />;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
let t1;
|
||||
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = <StaticText1 />;
|
||||
$[1] = t1;
|
||||
} else {
|
||||
t1 = $[1];
|
||||
}
|
||||
let t2;
|
||||
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t2 = (
|
||||
<div>
|
||||
Before text{t0}Middle text
|
||||
<StaticText1>
|
||||
Inner before text{t1}Inner middle text
|
||||
<StaticText1 />
|
||||
Inner after text
|
||||
</StaticText1>
|
||||
After text
|
||||
</div>
|
||||
);
|
||||
$[2] = t2;
|
||||
} else {
|
||||
t2 = $[2];
|
||||
}
|
||||
return t2;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { StaticText1 } from "shared-runtime";
|
||||
|
||||
function Component() {
|
||||
return (
|
||||
<div>
|
||||
Before text
|
||||
<StaticText1 />
|
||||
Middle text
|
||||
<StaticText1>
|
||||
Inner before text
|
||||
<StaticText1 />
|
||||
Inner middle text
|
||||
<StaticText1 />
|
||||
Inner after text
|
||||
</StaticText1>
|
||||
After text
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [],
|
||||
};
|
||||
@@ -469,6 +469,7 @@ const skipFilter = new Set([
|
||||
|
||||
// Bug in Forget output
|
||||
"todo-rename-source-variables",
|
||||
"bug-fbt-preserve-whitespace",
|
||||
|
||||
// Tested e2e in forget-feedback repo
|
||||
"userspace-use-memo-cache",
|
||||
|
||||
Reference in new issue
Block a user