Skip to content

Commit

Permalink
chore: ensure test app transpiles JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Mar 28, 2023
1 parent 7373104 commit ce65c56
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions app/client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
generateCallbackProps,
generatePropsAssignmentSource,
} from "@previewjs/properties";
import ts from "typescript";

const iframe = document.getElementById("root") as HTMLIFrameElement;
const rpcApi = createAxiosApi("/api/");
Expand Down Expand Up @@ -49,11 +50,30 @@ async function onUrlChanged() {
iframeController.loadComponent({
filePath,
componentName,
propsAssignmentSource: generatePropsAssignmentSource(
propsType,
autogenCallbackProps.keys,
computePropsResponse.types
propsAssignmentSource: transpile(
generatePropsAssignmentSource(
propsType,
autogenCallbackProps.keys,
computePropsResponse.types
)
),
autogenCallbackPropsSource: transpile(
`autogenCallbackProps = ${autogenCallbackProps.source}`
),
autogenCallbackPropsSource: autogenCallbackProps.source,
});
}

function transpile(source: string) {
// Transform JSX if required.
try {
return ts.transpileModule(source, {
compilerOptions: {
target: ts.ScriptTarget.ES2022,
jsx: ts.JsxEmit.React,
jsxFactory: "__jsxFactory__",
},
}).outputText;
} catch (e) {
throw new Error(`Error transforming source:\n${source}\n\n${e}`);
}
}

0 comments on commit ce65c56

Please sign in to comment.