Skip to content

Commit

Permalink
Replace @babel/standalone with sucrase for jsx compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Nov 12, 2023
1 parent 26828a5 commit d5f51f0
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-swans-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': minor
---

Replace `@babel/standalone` with `sucrase` for JSX compilation
12 changes: 0 additions & 12 deletions @types/babel__standalone.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/standalone": "^7.20.6",
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"@types/base64-url": "^2.2.0",
"@types/codemirror": "^5.60.5",
Expand Down Expand Up @@ -104,6 +103,7 @@
"react-use": "^17.4.0",
"read-pkg-up": "^7.0.1",
"scope-eval": "^1.0.0",
"sucrase": "^3.34.0",
"typescript": ">=5.0.0",
"use-debounce": "^9.0.2",
"webpack": "^5.75.0",
Expand Down
64 changes: 56 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface PlayroomConfig {
iframeSandbox?: string;
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
reactDocgenTypescriptConfig?: import('react-docgen-typescript').ParserOptions;
production?: boolean;
}

interface InternalPlayroomConfig extends PlayroomConfig {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/compileJsx.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { transform } from '@babel/standalone';
import { transform } from 'sucrase';
import playroomConfig from '../config';

export const openFragmentTag = '<React.Fragment>';
export const closeFragmentTag = '</React.Fragment>';

export const compileJsx = (code: string) =>
transform(`${openFragmentTag}${code.trim() || ''}${closeFragmentTag}`, {
presets: ['react'],
transforms: ['jsx'],
production: playroomConfig.production,
}).code;

export const validateCode = (code: string) => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"lib": ["dom", "es2022"],
"target": "es2022"
},
"include": ["src", "@types"],
"include": ["src"],
"exclude": ["cypress", "node_modules"]
}

0 comments on commit d5f51f0

Please sign in to comment.