Sprout tests to double-check our destructuring

I wanted to double-check the semantics of when default values are used, so i 
wrote out some fixtures with sprout enabled.
This commit is contained in:
Joe Savona
2023-09-07 17:17:03 -07:00
parent e8d130bd1d
commit edd9c52142
8 changed files with 172 additions and 0 deletions
@@ -0,0 +1,33 @@
## Input
```javascript
function Component(props) {
// destructure slot index has a hole in the input, should return default
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [, /* hole! */ 3.14] }],
};
```
## Code
```javascript
function Component(props) {
const [t18] = props.value;
const x = t18 === undefined ? 42 : t18;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [, /* hole! */ 3.14] }],
};
```
@@ -0,0 +1,10 @@
function Component(props) {
// destructure slot index has a hole in the input, should return default
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [, /* hole! */ 3.14] }],
};
@@ -0,0 +1,33 @@
## Input
```javascript
function Component(props) {
// destructure slot index has an explicit null in the input, should return null (not the default)
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [null] }],
};
```
## Code
```javascript
function Component(props) {
const [t18] = props.value;
const x = t18 === undefined ? 42 : t18;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [null] }],
};
```
@@ -0,0 +1,10 @@
function Component(props) {
// destructure slot index has an explicit null in the input, should return null (not the default)
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [null] }],
};
@@ -0,0 +1,33 @@
## Input
```javascript
function Component(props) {
// destructure slot index has an explicit undefined in the input, should return default
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [undefined] }],
};
```
## Code
```javascript
function Component(props) {
const [t18] = props.value;
const x = t18 === undefined ? 42 : t18;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [undefined] }],
};
```
@@ -0,0 +1,10 @@
function Component(props) {
// destructure slot index has an explicit undefined in the input, should return default
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [undefined] }],
};
@@ -0,0 +1,33 @@
## Input
```javascript
function Component(props) {
// destructure past end of empty array, should evaluate to default
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [] }],
};
```
## Code
```javascript
function Component(props) {
const [t18] = props.value;
const x = t18 === undefined ? 42 : t18;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [] }],
};
```
@@ -0,0 +1,10 @@
function Component(props) {
// destructure past end of empty array, should evaluate to default
const [x = 42] = props.value;
return x;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: [] }],
};