diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-array-hole.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-array-hole.expect.md new file mode 100644 index 0000000000..56bd6b9bb6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-array-hole.expect.md @@ -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] }], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-array-hole.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-array-hole.js new file mode 100644 index 0000000000..d1da06dbc2 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-array-hole.js @@ -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] }], +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-null.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-null.expect.md new file mode 100644 index 0000000000..82986535cf --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-null.expect.md @@ -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] }], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-null.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-null.js new file mode 100644 index 0000000000..14f1e3806c --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-null.js @@ -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] }], +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-undefined.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-undefined.expect.md new file mode 100644 index 0000000000..b78dcfd661 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-undefined.expect.md @@ -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] }], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-undefined.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-undefined.js new file mode 100644 index 0000000000..90ce975c54 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-at-explicit-undefined.js @@ -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] }], +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-past-end-of-array.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-past-end-of-array.expect.md new file mode 100644 index 0000000000..a4c9b6810e --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-past-end-of-array.expect.md @@ -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: [] }], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-past-end-of-array.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-past-end-of-array.js new file mode 100644 index 0000000000..0d37387950 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-default-past-end-of-array.js @@ -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: [] }], +};