More tests for AssignmentPattern
Joe Savona committed
Mar 27, 2023 at 10:34 UTC
4a826985db82be35a84e0681d2e47966dde95e67
5 files changed
+50
-4
compiler/forget/src/HIR/BuildHIR.ts
+2
-4
@@ -1795,16 +1795,14 @@ function lowerReorderableExpression(
1795
builder: HIRBuilder,
1796
expr: NodePath<t.Expression>
1797
): Place {
1798
- if (isReorderableExpression(builder, expr)) {
1799
- return lowerExpressionToTemporary(builder, expr);
1800
- } else {
1798
+ if (!isReorderableExpression(builder, expr)) {
1799
builder.errors.push({
1800
reason: `(BuildHIR::node.lowerReorderableExpression) Expression type '${expr.type}' cannot be safely reordered`,
1801
severity: ErrorSeverity.Todo,
1802
nodePath: expr,
1803
});
1806
- return buildTemporaryPlace(builder, expr.node.loc ?? GeneratedSource);
1804
}
1805
+ return lowerExpressionToTemporary(builder, expr);
1806
}
1807
1808
function isReorderableExpression(
compiler/forget/src/__tests__/fixtures/compiler/destructuring-array-param-default.expect.md
new
+21
@@ -0,0 +1,21 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component([a = 2]) {
6
+ return a;
7
+}
8
+
9
+```
10
+
11
+## Code
12
+
13
+```javascript
14
+function Component(t13) {
15
+ const [t14] = t13;
16
+ const a = t14 === undefined ? 2 : t14;
17
+ return a;
18
+}
19
+
20
+```
21
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/destructuring-array-param-default.js
new
+3
@@ -0,0 +1,3 @@
1
+function Component([a = 2]) {
2
+ return a;
3
+}
compiler/forget/src/__tests__/fixtures/compiler/destructuring-object-param-default.expect.md
new
+21
@@ -0,0 +1,21 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component({ a = 2 }) {
6
+ return a;
7
+}
8
+
9
+```
10
+
11
+## Code
12
+
13
+```javascript
14
+function Component(t13) {
15
+ const { a: t14 } = t13;
16
+ const a = t14 === undefined ? 2 : t14;
17
+ return a;
18
+}
19
+
20
+```
21
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/destructuring-object-param-default.js
new
+3
@@ -0,0 +1,3 @@
1
+function Component({ a = 2 }) {
2
+ return a;
3
+}