mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[alias] Don't alias primitives
This commit is contained in:
@@ -607,3 +607,7 @@ function phiTypeEquals(tA: Type, tB: Type): boolean {
|
||||
export function isObjectType(id: Identifier): boolean {
|
||||
return id.type.kind === "Object";
|
||||
}
|
||||
|
||||
export function isPrimitiveType(id: Identifier): boolean {
|
||||
return id.type.kind === "Primitive";
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
HIRFunction,
|
||||
Identifier,
|
||||
Instruction,
|
||||
isPrimitiveType,
|
||||
LValue,
|
||||
Place,
|
||||
} from "../HIR/HIR";
|
||||
@@ -33,6 +34,9 @@ function inferInstr(instr: Instruction, state: AliasAnalyser) {
|
||||
let alias: Place | null = null;
|
||||
switch (instrValue.kind) {
|
||||
case "Identifier": {
|
||||
if (isPrimitiveType(instrValue.identifier)) {
|
||||
return;
|
||||
}
|
||||
alias = instrValue;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
let x = "foo";
|
||||
if (a) {
|
||||
x = "bar";
|
||||
} else {
|
||||
x = "baz";
|
||||
}
|
||||
let y = x;
|
||||
mutate(y);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
const $ = React.useMemoCache();
|
||||
const x = "foo";
|
||||
const c_0 = $[0] !== a;
|
||||
let x$0;
|
||||
if (c_0) {
|
||||
x$0 = undefined;
|
||||
|
||||
if (a) {
|
||||
const x$1 = "bar";
|
||||
x$0 = x$1;
|
||||
} else {
|
||||
const x$2 = "baz";
|
||||
x$0 = x$2;
|
||||
}
|
||||
|
||||
$[0] = a;
|
||||
$[1] = x$0;
|
||||
} else {
|
||||
x$0 = $[1];
|
||||
}
|
||||
|
||||
const y = x$0;
|
||||
mutate(y);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
function component(a) {
|
||||
let x = "foo";
|
||||
if (a) {
|
||||
x = "bar";
|
||||
} else {
|
||||
x = "baz";
|
||||
}
|
||||
let y = x;
|
||||
mutate(y);
|
||||
return y;
|
||||
}
|
||||
Reference in New Issue
Block a user