refactor(jsx-explorer): replace @babel/core with @babel/standalone

This commit is contained in:
三咲智子 Kevin Deng
2024-09-07 05:04:05 +08:00
parent 455ae7182d
commit 4bd09577cc
4 changed files with 31 additions and 26 deletions

View File

@ -1,6 +1,6 @@
import * as monaco from 'monaco-editor';
import { watchEffect } from 'vue';
import { transform } from '@babel/core';
import { transform } from '@babel/standalone';
import babelPluginJsx from '@vue/babel-plugin-jsx';
// @ts-expect-error missing types
import typescript from '@babel/plugin-syntax-typescript';
@ -85,27 +85,21 @@ const App = defineComponent((props) => <div>Hello World</div>)`,
localStorage.setItem('state', state);
window.location.hash = encodeURIComponent(src);
console.clear();
transform(
src,
{
try {
const res = transform(src, {
babelrc: false,
plugins: [
[babelPluginJsx, { ...compilerOptions }],
[typescript, { isTSX: true }],
],
ast: true,
},
(err, result = {}) => {
const res = result!;
if (!err) {
console.log('AST', res.ast!);
output.setValue(res.code!);
} else {
console.error(err);
output.setValue(err.message!);
}
}
);
});
console.log('AST', res.ast!);
output.setValue(res.code!);
} catch (err: any) {
console.error(err);
output.setValue(err.message!);
}
};
// handle resize