diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts index 29aa632222..92169a9599 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts @@ -1927,6 +1927,12 @@ function lowerExpression( let value; if (valueExpr.isJSXElement() || valueExpr.isStringLiteral()) { value = lowerExpressionToTemporary(builder, valueExpr); + } else if (valueExpr.type == null) { + value = lowerValueToTemporary(builder, { + kind: "Primitive", + value: true, + loc: attribute.node.loc ?? GeneratedSource, + }); } else { if (!valueExpr.isJSXExpressionContainer()) { builder.errors.push({ diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-attribute-default-to-true.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-attribute-default-to-true.expect.md new file mode 100644 index 0000000000..e1b59d19c6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-attribute-default-to-true.expect.md @@ -0,0 +1,43 @@ + +## Input + +```javascript +import { Stringify } from "shared-runtime"; + +function Component() { + // https://legacy.reactjs.org/docs/jsx-in-depth.html#props-default-to-true + return ; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +}; + +``` + +## Code + +```javascript +import { unstable_useMemoCache as useMemoCache } from "react"; +import { Stringify } from "shared-runtime"; + +function Component() { + const $ = useMemoCache(1); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t0 = ; + $[0] = t0; + } else { + t0 = $[0]; + } + return t0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-attribute-default-to-true.tsx b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-attribute-default-to-true.tsx new file mode 100644 index 0000000000..63dc0a68cd --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-attribute-default-to-true.tsx @@ -0,0 +1,11 @@ +import { Stringify } from "shared-runtime"; + +function Component() { + // https://legacy.reactjs.org/docs/jsx-in-depth.html#props-default-to-true + return ; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/tsconfig.json b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/tsconfig.json index 5e3f769361..c4e800fe03 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/tsconfig.json +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/tsconfig.json @@ -4,6 +4,7 @@ { "compilerOptions": { "allowJs": true, + "isolatedModules": true, "noEmit": true, "noImplicitAny": false, "noUncheckedIndexedAccess": false, diff --git a/compiler/packages/sprout/src/shared-runtime.ts b/compiler/packages/sprout/src/shared-runtime.ts index 991518af19..f266a5e519 100644 --- a/compiler/packages/sprout/src/shared-runtime.ts +++ b/compiler/packages/sprout/src/shared-runtime.ts @@ -135,6 +135,7 @@ export function Text(props: { return React.createElement("div", null, props.value, props.children); } + export function StaticText1(props: { children?: Array }) { return React.createElement("div", null, "StaticText1", props.children); } @@ -154,8 +155,12 @@ export function RenderPropAsChild(props: { ); } -export function Stringify(props: any) { - return toJSON(props); +export function Stringify(props: any): React.ReactElement { + return React.createElement( + "div", + null, + toJSON(props), + ); } // helper functions