mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-01-10 08:19:10 +08:00
feat(jsx-explorer): support tsx
This commit is contained in:
parent
d99206b059
commit
20ef600064
@ -2,6 +2,8 @@ import * as monaco from 'monaco-editor';
|
|||||||
import { watchEffect } from 'vue';
|
import { watchEffect } from 'vue';
|
||||||
import { transform } from '@babel/core';
|
import { transform } from '@babel/core';
|
||||||
import babelPluginJsx from '@vue/babel-plugin-jsx';
|
import babelPluginJsx from '@vue/babel-plugin-jsx';
|
||||||
|
// @ts-expect-error missing types
|
||||||
|
import typescript from '@babel/plugin-syntax-typescript';
|
||||||
import {
|
import {
|
||||||
type VueJSXPluginOptions,
|
type VueJSXPluginOptions,
|
||||||
compilerOptions,
|
compilerOptions,
|
||||||
@ -25,6 +27,8 @@ function main() {
|
|||||||
|
|
||||||
const sharedEditorOptions: monaco.editor.IStandaloneEditorConstructionOptions =
|
const sharedEditorOptions: monaco.editor.IStandaloneEditorConstructionOptions =
|
||||||
{
|
{
|
||||||
|
language: 'typescript',
|
||||||
|
tabSize: 2,
|
||||||
theme: 'vs-dark',
|
theme: 'vs-dark',
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
wordWrap: 'on',
|
wordWrap: 'on',
|
||||||
@ -36,29 +40,37 @@ function main() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
||||||
|
noSemanticValidation: true,
|
||||||
|
});
|
||||||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
|
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
|
||||||
allowJs: true,
|
allowJs: true,
|
||||||
allowNonTsExtensions: true,
|
allowNonTsExtensions: true,
|
||||||
jsx: monaco.languages.typescript.JsxEmit.Preserve,
|
jsx: monaco.languages.typescript.JsxEmit.Preserve,
|
||||||
target: monaco.languages.typescript.ScriptTarget.Latest,
|
target: monaco.languages.typescript.ScriptTarget.Latest,
|
||||||
|
module: monaco.languages.typescript.ModuleKind.ESNext,
|
||||||
|
isolatedModules: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const editor = monaco.editor.create(document.getElementById('source')!, {
|
const editor = monaco.editor.create(document.getElementById('source')!, {
|
||||||
value:
|
|
||||||
decodeURIComponent(window.location.hash.slice(1)) ||
|
|
||||||
persistedState.src ||
|
|
||||||
'const App = () => <div>Hello World</div>',
|
|
||||||
language: 'typescript',
|
|
||||||
tabSize: 2,
|
|
||||||
...sharedEditorOptions,
|
...sharedEditorOptions,
|
||||||
|
model: monaco.editor.createModel(
|
||||||
|
decodeURIComponent(window.location.hash.slice(1)) ||
|
||||||
|
persistedState.src ||
|
||||||
|
'const App = () => <div>Hello World</div>',
|
||||||
|
'typescript',
|
||||||
|
monaco.Uri.parse('file:///app.tsx')
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const output = monaco.editor.create(document.getElementById('output')!, {
|
const output = monaco.editor.create(document.getElementById('output')!, {
|
||||||
value: '',
|
|
||||||
language: 'javascript',
|
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
tabSize: 2,
|
|
||||||
...sharedEditorOptions,
|
...sharedEditorOptions,
|
||||||
|
model: monaco.editor.createModel(
|
||||||
|
'',
|
||||||
|
'typescript',
|
||||||
|
monaco.Uri.parse('file:///output.tsx')
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const reCompile = () => {
|
const reCompile = () => {
|
||||||
@ -74,7 +86,10 @@ function main() {
|
|||||||
src,
|
src,
|
||||||
{
|
{
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
plugins: [[babelPluginJsx, { ...compilerOptions }]],
|
plugins: [
|
||||||
|
[babelPluginJsx, { ...compilerOptions }],
|
||||||
|
[typescript, { isTSX: true }],
|
||||||
|
],
|
||||||
ast: true,
|
ast: true,
|
||||||
},
|
},
|
||||||
(err, result = {}) => {
|
(err, result = {}) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user