mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Use shorthand where possible for ObjectExpression properties
During codegen, emit object properties as shorthand where possible (`{x}`
instead of `{x: x}`)
This commit is contained in:
@@ -591,10 +591,14 @@ function codegenInstructionValue(
|
||||
const properties = [];
|
||||
for (const property of instrValue.properties) {
|
||||
if (property.kind === "ObjectProperty") {
|
||||
const key = t.identifier(property.name);
|
||||
const value = codegenPlace(cx, property.place);
|
||||
properties.push(
|
||||
t.objectProperty(
|
||||
t.stringLiteral(property.name),
|
||||
codegenPlace(cx, property.place)
|
||||
key,
|
||||
value,
|
||||
false,
|
||||
value.type === "Identifier" && value.name === key.name
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ function component(a) {
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
const x = { a: a };
|
||||
const x = { a };
|
||||
|
||||
(function () {
|
||||
y = x;
|
||||
|
||||
@@ -21,7 +21,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let x;
|
||||
if (c_0) {
|
||||
x = { a: a };
|
||||
x = { a };
|
||||
const y = {};
|
||||
y.x = x.a;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ function component(t) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,7 @@ function component(a, b) {
|
||||
const c_0 = $[0] !== b;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { b: b };
|
||||
t0 = { b };
|
||||
$[0] = b;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
@@ -34,7 +34,7 @@ function component(a, b) {
|
||||
const c_2 = $[2] !== a;
|
||||
let t1;
|
||||
if (c_2) {
|
||||
t1 = { a: a };
|
||||
t1 = { a };
|
||||
$[2] = a;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let x;
|
||||
if (c_0) {
|
||||
x = { a: a };
|
||||
x = { a };
|
||||
(function () {
|
||||
let q = x;
|
||||
(function () {
|
||||
|
||||
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let z;
|
||||
if (c_0) {
|
||||
z = { a: a };
|
||||
z = { a };
|
||||
(function () {
|
||||
(function () {
|
||||
z.b = 1;
|
||||
|
||||
@@ -20,7 +20,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
|
||||
const c_1 = $[1] !== bar;
|
||||
let x;
|
||||
if (c_0 || c_1) {
|
||||
x = { foo: foo };
|
||||
const y = { bar: bar };
|
||||
x = { foo };
|
||||
const y = { bar };
|
||||
(function () {
|
||||
let a = { y };
|
||||
let b = x;
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
|
||||
const c_1 = $[1] !== bar;
|
||||
let x;
|
||||
if (c_0 || c_1) {
|
||||
x = { foo: foo };
|
||||
const y = { bar: bar };
|
||||
x = { foo };
|
||||
const y = { bar };
|
||||
(function () {
|
||||
let a = [y];
|
||||
let b = x;
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
|
||||
const c_1 = $[1] !== bar;
|
||||
let y;
|
||||
if (c_0 || c_1) {
|
||||
const x = { foo: foo };
|
||||
y = { bar: bar };
|
||||
const x = { foo };
|
||||
y = { bar };
|
||||
(function () {
|
||||
let a = [y];
|
||||
let b = x;
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
|
||||
const c_1 = $[1] !== bar;
|
||||
let y;
|
||||
if (c_0 || c_1) {
|
||||
const x = { foo: foo };
|
||||
y = { bar: bar };
|
||||
const x = { foo };
|
||||
y = { bar };
|
||||
(function () {
|
||||
let a = { y };
|
||||
let b = x;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let y;
|
||||
if (c_0) {
|
||||
const x = { a: a };
|
||||
const x = { a };
|
||||
y = {};
|
||||
(function () {
|
||||
y["x"] = x;
|
||||
|
||||
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let y;
|
||||
if (c_0) {
|
||||
const x = { a: a };
|
||||
const x = { a };
|
||||
y = {};
|
||||
(function () {
|
||||
y.x = x;
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let y;
|
||||
if (c_0) {
|
||||
const x = { a: a };
|
||||
const x = { a };
|
||||
y = {};
|
||||
(function () {
|
||||
let a = y;
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let y;
|
||||
if (c_0) {
|
||||
const x = { a: a };
|
||||
const x = { a };
|
||||
y = {};
|
||||
(function () {
|
||||
let a = y;
|
||||
|
||||
@@ -23,7 +23,7 @@ function component(a, b) {
|
||||
const c_0 = $[0] !== b;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { b: b };
|
||||
t0 = { b };
|
||||
$[0] = b;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
@@ -34,7 +34,7 @@ function component(a, b) {
|
||||
const c_3 = $[3] !== y.b;
|
||||
let x;
|
||||
if (c_2 || c_3) {
|
||||
const z = { a: a };
|
||||
const z = { a };
|
||||
x = function () {
|
||||
z.a = 2;
|
||||
y.b;
|
||||
|
||||
@@ -22,7 +22,7 @@ function component(a, b) {
|
||||
const c_0 = $[0] !== b;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { b: b };
|
||||
t0 = { b };
|
||||
$[0] = b;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
@@ -32,7 +32,7 @@ function component(a, b) {
|
||||
const c_2 = $[2] !== a;
|
||||
let t1;
|
||||
if (c_2) {
|
||||
t1 = { a: a };
|
||||
t1 = { a };
|
||||
$[2] = a;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
|
||||
@@ -21,7 +21,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let x;
|
||||
if (c_0) {
|
||||
const y = { b: { a: a } };
|
||||
const y = { b: { a } };
|
||||
x = function () {
|
||||
y.b.a = 2;
|
||||
};
|
||||
|
||||
@@ -24,11 +24,11 @@ function component(a, b) {
|
||||
const c_1 = $[1] !== b;
|
||||
let x;
|
||||
if (c_0 || c_1) {
|
||||
const z = { a: a };
|
||||
const z = { a };
|
||||
const c_3 = $[3] !== b;
|
||||
let t0;
|
||||
if (c_3) {
|
||||
t0 = { b: b };
|
||||
t0 = { b };
|
||||
$[3] = b;
|
||||
$[4] = t0;
|
||||
} else {
|
||||
|
||||
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let y;
|
||||
if (c_0) {
|
||||
const x = { a: a };
|
||||
const x = { a };
|
||||
y = {};
|
||||
(function () {
|
||||
y = x;
|
||||
|
||||
@@ -20,7 +20,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
@@ -21,8 +21,8 @@ function component(a, b) {
|
||||
const c_1 = $[1] !== b;
|
||||
let x;
|
||||
if (c_0 || c_1) {
|
||||
const y = { a: a };
|
||||
x = { b: b };
|
||||
const y = { a };
|
||||
x = { b };
|
||||
x.y = y;
|
||||
|
||||
mutate(x);
|
||||
|
||||
@@ -19,7 +19,7 @@ function component(a) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a, someGlobal: someGlobal };
|
||||
t0 = { a, someGlobal };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
|
||||
@@ -45,7 +45,7 @@ function foo(a, b, c) {
|
||||
const c_3 = $[3] !== o;
|
||||
let t0;
|
||||
if (c_0 || c_1 || c_2 || c_3) {
|
||||
t0 = { d: d, g: g, n: n, o: o };
|
||||
t0 = { d, g, n, o };
|
||||
$[0] = d;
|
||||
$[1] = g;
|
||||
$[2] = n;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ function foo(a, b, c) {
|
||||
const c_2 = $[2] !== c;
|
||||
let x;
|
||||
if (c_0 || c_1 || c_2) {
|
||||
x = { a: a };
|
||||
x = { a };
|
||||
const c_4 = $[4] !== b;
|
||||
const c_5 = $[5] !== c;
|
||||
let t0;
|
||||
|
||||
@@ -15,7 +15,7 @@ function Component(c) {
|
||||
|
||||
```javascript
|
||||
function Component(c) {
|
||||
const x = { c: c };
|
||||
const x = { c };
|
||||
mutate(x);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ function component(props) {
|
||||
const c_5 = $[5] !== b;
|
||||
let t2;
|
||||
if (c_4 || c_5) {
|
||||
t2 = { a: a, b: b };
|
||||
t2 = { a, b };
|
||||
$[4] = a;
|
||||
$[5] = b;
|
||||
$[6] = t2;
|
||||
|
||||
@@ -44,7 +44,7 @@ function Component(props) {
|
||||
const a = {};
|
||||
const b = [a];
|
||||
const c = {};
|
||||
const d = { c: c };
|
||||
const d = { c };
|
||||
|
||||
const x = {};
|
||||
x.b = b;
|
||||
|
||||
@@ -25,7 +25,7 @@ function foo(a, b, c, d) {
|
||||
const c_0 = $[0] !== b;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { b: b };
|
||||
t0 = { b };
|
||||
$[0] = b;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
@@ -36,7 +36,7 @@ function foo(a, b, c, d) {
|
||||
const c_2 = $[2] !== c;
|
||||
let t1;
|
||||
if (c_2) {
|
||||
t1 = { c: c };
|
||||
t1 = { c };
|
||||
$[2] = c;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -27,9 +27,9 @@ function foo(a, b, c, d) {
|
||||
if (c_0 || c_1) {
|
||||
x = undefined;
|
||||
if (someVal) {
|
||||
x = { b: b };
|
||||
x = { b };
|
||||
} else {
|
||||
x = { c: c };
|
||||
x = { c };
|
||||
}
|
||||
x.f = 1;
|
||||
$[0] = b;
|
||||
|
||||
@@ -19,7 +19,7 @@ function component(t16) {
|
||||
const c_0 = $[0] !== a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { a: a };
|
||||
t0 = { a };
|
||||
$[0] = a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
@@ -29,7 +29,7 @@ function component(t16) {
|
||||
const c_2 = $[2] !== b;
|
||||
let t1;
|
||||
if (c_2) {
|
||||
t1 = { b: b };
|
||||
t1 = { b };
|
||||
$[2] = b;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
@@ -40,7 +40,7 @@ function component(t16) {
|
||||
const c_5 = $[5] !== z;
|
||||
let t2;
|
||||
if (c_4 || c_5) {
|
||||
t2 = { y: y, z: z };
|
||||
t2 = { y, z };
|
||||
$[4] = y;
|
||||
$[5] = z;
|
||||
$[6] = t2;
|
||||
|
||||
@@ -21,7 +21,7 @@ function component(a, b) {
|
||||
const c_1 = $[1] !== b;
|
||||
let t0;
|
||||
if (c_0 || c_1) {
|
||||
t0 = { a: a, b: b };
|
||||
t0 = { a, b };
|
||||
$[0] = a;
|
||||
$[1] = b;
|
||||
$[2] = t0;
|
||||
|
||||
@@ -28,7 +28,7 @@ function foo() {
|
||||
const y = 3;
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = { x: x, y: y };
|
||||
t0 = { x, y };
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
|
||||
@@ -19,7 +19,7 @@ function foo() {
|
||||
let y;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
const x = [];
|
||||
y = { x: x };
|
||||
y = { x };
|
||||
y.x.push([]);
|
||||
$[0] = y;
|
||||
} else {
|
||||
|
||||
@@ -47,7 +47,7 @@ function component(a) {
|
||||
const c_8 = $[8] !== f;
|
||||
let t1;
|
||||
if (c_2 || c_3 || c_4 || c_5 || c_6 || c_7 || c_8) {
|
||||
t1 = { z: z, p: p, q: q, n: n, m: m, e: e, f: f };
|
||||
t1 = { z, p, q, n, m, e, f };
|
||||
$[2] = z;
|
||||
$[3] = p;
|
||||
$[4] = q;
|
||||
|
||||
@@ -26,7 +26,7 @@ function foo(props) {
|
||||
const c_2 = $[2] !== z;
|
||||
let t0;
|
||||
if (c_0 || c_1 || c_2) {
|
||||
t0 = { x: x, y: y, z: z };
|
||||
t0 = { x, y, z };
|
||||
$[0] = x;
|
||||
$[1] = y;
|
||||
$[2] = z;
|
||||
|
||||
Reference in New Issue
Block a user