Skip to content

Commit

Permalink
chore(BuildTool): fix live demo code
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 committed Jan 11, 2024
1 parent b3016cf commit 74c7cf1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tools/build/docs/render-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export async function getDemoRenderScript(
) {
const liveArr = getLiveScript(js);
const liveVars = liveArr[1];
const liveScript = (await transform(liveArr[0]))
const liveScript = (await transform(liveArr[0], 'preserve'))
.replace(/`/g, '\\`')
.replace(/\$/g, '\\$')
.replace(/\n$/, '');
Expand Down
3 changes: 2 additions & 1 deletion tools/build/docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ export function parse(md: string) {

const TSCONFIG_PATH = path.resolve(CWD, 'tsconfig.json');

export async function transform(code: string) {
export async function transform(code: string, jsx?: 'transform' | 'preserve') {
const tsconfig = await getRegularTsconfigJson(fs.readFileSync(TSCONFIG_PATH, 'utf-8'));
try {

const result = await esbuildTransform(code, {
format: 'cjs',
loader: 'tsx',
jsx,
tsconfigRaw: JSON.stringify({ compilerOptions: tsconfig.compilerOptions }),
});
return result.code;
Expand Down

0 comments on commit 74c7cf1

Please sign in to comment.