Use shorthand where possible for ObjectExpression properties
During codegen, emit object properties as shorthand where possible (`{x}` instead of `{x: x}`)
Joe Savona committed
Mar 6, 2023 at 16:35 UTC
1c023263a3a5ea7c5abf05e75598a84ca6c56c53
44 files changed
+62
-58
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+6
-2
@@ -591,10 +591,14 @@ function codegenInstructionValue(
591
const properties = [];
592
for (const property of instrValue.properties) {
593
if (property.kind === "ObjectProperty") {
594
+ const key = t.identifier(property.name);
595
+ const value = codegenPlace(cx, property.place);
596
properties.push(
597
t.objectProperty(
596
- t.stringLiteral(property.name),
597
- codegenPlace(cx, property.place)
598
+ key,
599
+ value,
600
+ false,
601
+ value.type === "Identifier" && value.name === key.name
602
)
603
);
604
} else {
compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.expect.md
+1
-1
@@ -18,7 +18,7 @@ function component(a) {
18
19
```javascript
20
function component(a) {
21
- const x = { a: a };
21
+ const x = { a };
22
23
(function () {
24
y = x;
compiler/forget/src/__tests__/fixtures/hir/alias-computed-load.expect.md
+1
-1
@@ -21,7 +21,7 @@ function component(a) {
21
const c_0 = $[0] !== a;
22
let x;
23
if (c_0) {
24
- x = { a: a };
24
+ x = { a };
25
const y = {};
26
y.x = x.a;
27
compiler/forget/src/__tests__/fixtures/hir/bug_object-pattern.expect.md
+1
-1
@@ -19,7 +19,7 @@ function component(t) {
19
const c_0 = $[0] !== a;
20
let t0;
21
if (c_0) {
22
- t0 = { a: a };
22
+ t0 = { a };
23
$[0] = a;
24
$[1] = t0;
25
} else {
compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.expect.md
+2
-2
@@ -24,7 +24,7 @@ function component(a, b) {
24
const c_0 = $[0] !== b;
25
let t0;
26
if (c_0) {
27
- t0 = { b: b };
27
+ t0 = { b };
28
$[0] = b;
29
$[1] = t0;
30
} else {
@@ -34,7 +34,7 @@ function component(a, b) {
34
const c_2 = $[2] !== a;
35
let t1;
36
if (c_2) {
37
- t1 = { a: a };
37
+ t1 = { a };
38
$[2] = a;
39
$[3] = t1;
40
} else {
compiler/forget/src/__tests__/fixtures/hir/capture-indirect-mutate-alias.expect.md
+1
-1
@@ -24,7 +24,7 @@ function component(a) {
24
const c_0 = $[0] !== a;
25
let x;
26
if (c_0) {
27
- x = { a: a };
27
+ x = { a };
28
(function () {
29
let q = x;
30
(function () {
compiler/forget/src/__tests__/fixtures/hir/capture_mutate-across-fns.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let z;
24
if (c_0) {
25
- z = { a: a };
25
+ z = { a };
26
(function () {
27
(function () {
28
z.b = 1;
compiler/forget/src/__tests__/fixtures/hir/capturing-arrow-function-1.expect.md
+1
-1
@@ -20,7 +20,7 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t0;
22
if (c_0) {
23
- t0 = { a: a };
23
+ t0 = { a };
24
$[0] = a;
25
$[1] = t0;
26
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-fun-alias-captured-mutate-2.expect.md
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
25
const c_1 = $[1] !== bar;
26
let x;
27
if (c_0 || c_1) {
28
- x = { foo: foo };
29
- const y = { bar: bar };
28
+ x = { foo };
29
+ const y = { bar };
30
(function () {
31
let a = { y };
32
let b = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-fun-alias-captured-mutate-arr-2.expect.md
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
25
const c_1 = $[1] !== bar;
26
let x;
27
if (c_0 || c_1) {
28
- x = { foo: foo };
29
- const y = { bar: bar };
28
+ x = { foo };
29
+ const y = { bar };
30
(function () {
31
let a = [y];
32
let b = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-alias-captured-mutate-arr.expect.md
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
25
const c_1 = $[1] !== bar;
26
let y;
27
if (c_0 || c_1) {
28
- const x = { foo: foo };
29
- y = { bar: bar };
28
+ const x = { foo };
29
+ y = { bar };
30
(function () {
31
let a = [y];
32
let b = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-alias-captured-mutate.expect.md
+2
-2
@@ -25,8 +25,8 @@ function component(foo, bar) {
25
const c_1 = $[1] !== bar;
26
let y;
27
if (c_0 || c_1) {
28
- const x = { foo: foo };
29
- y = { bar: bar };
28
+ const x = { foo };
29
+ y = { bar };
30
(function () {
31
let a = { y };
32
let b = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-alias-computed-mutate.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let y;
24
if (c_0) {
25
- const x = { a: a };
25
+ const x = { a };
26
y = {};
27
(function () {
28
y["x"] = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-alias-mutate.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let y;
24
if (c_0) {
25
- const x = { a: a };
25
+ const x = { a };
26
y = {};
27
(function () {
28
y.x = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-alias-receiver-computed-mutate.expect.md
+1
-1
@@ -23,7 +23,7 @@ function component(a) {
23
const c_0 = $[0] !== a;
24
let y;
25
if (c_0) {
26
- const x = { a: a };
26
+ const x = { a };
27
y = {};
28
(function () {
29
let a = y;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-alias-receiver-mutate.expect.md
+1
-1
@@ -23,7 +23,7 @@ function component(a) {
23
const c_0 = $[0] !== a;
24
let y;
25
if (c_0) {
26
- const x = { a: a };
26
+ const x = { a };
27
y = {};
28
(function () {
29
let a = y;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-mutate-2.expect.md
+2
-2
@@ -23,7 +23,7 @@ function component(a, b) {
23
const c_0 = $[0] !== b;
24
let t0;
25
if (c_0) {
26
- t0 = { b: b };
26
+ t0 = { b };
27
$[0] = b;
28
$[1] = t0;
29
} else {
@@ -34,7 +34,7 @@ function component(a, b) {
34
const c_3 = $[3] !== y.b;
35
let x;
36
if (c_2 || c_3) {
37
- const z = { a: a };
37
+ const z = { a };
38
x = function () {
39
z.a = 2;
40
y.b;
compiler/forget/src/__tests__/fixtures/hir/capturing-func-mutate-3.expect.md
+2
-2
@@ -22,7 +22,7 @@ function component(a, b) {
22
const c_0 = $[0] !== b;
23
let t0;
24
if (c_0) {
25
- t0 = { b: b };
25
+ t0 = { b };
26
$[0] = b;
27
$[1] = t0;
28
} else {
@@ -32,7 +32,7 @@ function component(a, b) {
32
const c_2 = $[2] !== a;
33
let t1;
34
if (c_2) {
35
- t1 = { a: a };
35
+ t1 = { a };
36
$[2] = a;
37
$[3] = t1;
38
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-func-mutate-nested.expect.md
+1
-1
@@ -21,7 +21,7 @@ function component(a) {
21
const c_0 = $[0] !== a;
22
let x;
23
if (c_0) {
24
- const y = { b: { a: a } };
24
+ const y = { b: { a } };
25
x = function () {
26
y.b.a = 2;
27
};
compiler/forget/src/__tests__/fixtures/hir/capturing-func-mutate.expect.md
+2
-2
@@ -24,11 +24,11 @@ function component(a, b) {
24
const c_1 = $[1] !== b;
25
let x;
26
if (c_0 || c_1) {
27
- const z = { a: a };
27
+ const z = { a };
28
const c_3 = $[3] !== b;
29
let t0;
30
if (c_3) {
31
- t0 = { b: b };
31
+ t0 = { b };
32
$[3] = b;
33
$[4] = t0;
34
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-func-simple-alias.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let y;
24
if (c_0) {
25
- const x = { a: a };
25
+ const x = { a };
26
y = {};
27
(function () {
28
y = x;
compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md
+1
-1
@@ -20,7 +20,7 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t0;
22
if (c_0) {
23
- t0 = { a: a };
23
+ t0 = { a };
24
$[0] = a;
25
$[1] = t0;
26
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md
+1
-1
@@ -23,7 +23,7 @@ function component(a) {
23
const c_0 = $[0] !== a;
24
let t0;
25
if (c_0) {
26
- t0 = { a: a };
26
+ t0 = { a };
27
$[0] = a;
28
$[1] = t0;
29
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-member-expr.expect.md
+1
-1
@@ -20,7 +20,7 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t0;
22
if (c_0) {
23
- t0 = { a: a };
23
+ t0 = { a };
24
$[0] = a;
25
$[1] = t0;
26
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-call.expect.md
+1
-1
@@ -20,7 +20,7 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t0;
22
if (c_0) {
23
- t0 = { a: a };
23
+ t0 = { a };
24
$[0] = a;
25
$[1] = t0;
26
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr-in-nested-func.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let t0;
24
if (c_0) {
25
- t0 = { a: a };
25
+ t0 = { a };
26
$[0] = a;
27
$[1] = t0;
28
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr.expect.md
+1
-1
@@ -20,7 +20,7 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t0;
22
if (c_0) {
23
- t0 = { a: a };
23
+ t0 = { a };
24
$[0] = a;
25
$[1] = t0;
26
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let t0;
24
if (c_0) {
25
- t0 = { a: a };
25
+ t0 = { a };
26
$[0] = a;
27
$[1] = t0;
28
} else {
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md
+1
-1
@@ -22,7 +22,7 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let t0;
24
if (c_0) {
25
- t0 = { a: a };
25
+ t0 = { a };
26
$[0] = a;
27
$[1] = t0;
28
} else {
compiler/forget/src/__tests__/fixtures/hir/computed-store-alias.expect.md
+2
-2
@@ -21,8 +21,8 @@ function component(a, b) {
21
const c_1 = $[1] !== b;
22
let x;
23
if (c_0 || c_1) {
24
- const y = { a: a };
25
- x = { b: b };
24
+ const y = { a };
25
+ x = { b };
26
x.y = y;
27
28
mutate(x);
compiler/forget/src/__tests__/fixtures/hir/destructure-capture-global.expect.md
+1
-1
@@ -19,7 +19,7 @@ function component(a) {
19
const c_0 = $[0] !== a;
20
let t0;
21
if (c_0) {
22
- t0 = { a: a, someGlobal: someGlobal };
22
+ t0 = { a, someGlobal };
23
$[0] = a;
24
$[1] = t0;
25
} else {
compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md
+1
-1
@@ -45,7 +45,7 @@ function foo(a, b, c) {
45
const c_3 = $[3] !== o;
46
let t0;
47
if (c_0 || c_1 || c_2 || c_3) {
48
- t0 = { d: d, g: g, n: n, o: o };
48
+ t0 = { d, g, n, o };
49
$[0] = d;
50
$[1] = g;
51
$[2] = n;
compiler/forget/src/__tests__/fixtures/hir/independently-memoize-object-property.expect.md
+1
-1
@@ -22,7 +22,7 @@ function foo(a, b, c) {
22
const c_2 = $[2] !== c;
23
let x;
24
if (c_0 || c_1 || c_2) {
25
- x = { a: a };
25
+ x = { a };
26
const c_4 = $[4] !== b;
27
const c_5 = $[5] !== c;
28
let t0;
compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md
+1
-1
@@ -15,7 +15,7 @@ function Component(c) {
15
16
```javascript
17
function Component(c) {
18
- const x = { c: c };
18
+ const x = { c };
19
mutate(x);
20
}
21
compiler/forget/src/__tests__/fixtures/hir/logical-expression-object.expect.md
+1
-1
@@ -44,7 +44,7 @@ function component(props) {
44
const c_5 = $[5] !== b;
45
let t2;
46
if (c_4 || c_5) {
47
- t2 = { a: a, b: b };
47
+ t2 = { a, b };
48
$[4] = a;
49
$[5] = b;
50
$[6] = t2;
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md
+1
-1
@@ -44,7 +44,7 @@ function Component(props) {
44
const a = {};
45
const b = [a];
46
const c = {};
47
- const d = { c: c };
47
+ const d = { c };
48
49
const x = {};
50
x.b = b;
compiler/forget/src/__tests__/fixtures/hir/obj-literal-cached-in-if-else.expect.md
+2
-2
@@ -25,7 +25,7 @@ function foo(a, b, c, d) {
25
const c_0 = $[0] !== b;
26
let t0;
27
if (c_0) {
28
- t0 = { b: b };
28
+ t0 = { b };
29
$[0] = b;
30
$[1] = t0;
31
} else {
@@ -36,7 +36,7 @@ function foo(a, b, c, d) {
36
const c_2 = $[2] !== c;
37
let t1;
38
if (c_2) {
39
- t1 = { c: c };
39
+ t1 = { c };
40
$[2] = c;
41
$[3] = t1;
42
} else {
compiler/forget/src/__tests__/fixtures/hir/obj-literal-mutated-after-if-else.expect.md
+2
-2
@@ -27,9 +27,9 @@ function foo(a, b, c, d) {
27
if (c_0 || c_1) {
28
x = undefined;
29
if (someVal) {
30
- x = { b: b };
30
+ x = { b };
31
} else {
32
- x = { c: c };
32
+ x = { c };
33
}
34
x.f = 1;
35
$[0] = b;
compiler/forget/src/__tests__/fixtures/hir/object-pattern-params.expect.md
+3
-3
@@ -19,7 +19,7 @@ function component(t16) {
19
const c_0 = $[0] !== a;
20
let t0;
21
if (c_0) {
22
- t0 = { a: a };
22
+ t0 = { a };
23
$[0] = a;
24
$[1] = t0;
25
} else {
@@ -29,7 +29,7 @@ function component(t16) {
29
const c_2 = $[2] !== b;
30
let t1;
31
if (c_2) {
32
- t1 = { b: b };
32
+ t1 = { b };
33
$[2] = b;
34
$[3] = t1;
35
} else {
@@ -40,7 +40,7 @@ function component(t16) {
40
const c_5 = $[5] !== z;
41
let t2;
42
if (c_4 || c_5) {
43
- t2 = { y: y, z: z };
43
+ t2 = { y, z };
44
$[4] = y;
45
$[5] = z;
46
$[6] = t2;
compiler/forget/src/__tests__/fixtures/hir/prop-capturing-function-1.expect.md
+1
-1
@@ -21,7 +21,7 @@ function component(a, b) {
21
const c_1 = $[1] !== b;
22
let t0;
23
if (c_0 || c_1) {
24
- t0 = { a: a, b: b };
24
+ t0 = { a, b };
25
$[0] = a;
26
$[1] = b;
27
$[2] = t0;
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md
+1
-1
@@ -28,7 +28,7 @@ function foo() {
28
const y = 3;
29
let t0;
30
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31
- t0 = { x: x, y: y };
31
+ t0 = { x, y };
32
$[0] = t0;
33
} else {
34
t0 = $[0];
compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md
+1
-1
@@ -19,7 +19,7 @@ function foo() {
19
let y;
20
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21
const x = [];
22
- y = { x: x };
22
+ y = { x };
23
y.x.push([]);
24
$[0] = y;
25
} else {
compiler/forget/src/__tests__/fixtures/hir/unary-expr.expect.md
+1
-1
@@ -47,7 +47,7 @@ function component(a) {
47
const c_8 = $[8] !== f;
48
let t1;
49
if (c_2 || c_3 || c_4 || c_5 || c_6 || c_7 || c_8) {
50
- t1 = { z: z, p: p, q: q, n: n, m: m, e: e, f: f };
50
+ t1 = { z, p, q, n, m, e, f };
51
$[2] = z;
52
$[3] = p;
53
$[4] = q;
compiler/forget/src/__tests__/fixtures/hir/update-expression.expect.md
+1
-1
@@ -26,7 +26,7 @@ function foo(props) {
26
const c_2 = $[2] !== z;
27
let t0;
28
if (c_0 || c_1 || c_2) {
29
- t0 = { x: x, y: y, z: z };
29
+ t0 = { x, y, z };
30
$[0] = x;
31
$[1] = y;
32
$[2] = z;