Skip to content

Commit 3456cf5

Browse files
committed
feat!: remove @babel/plugin-syntax-typescript dep
1 parent b6fc6fa commit 3456cf5

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ VueJsx({
117117
],
118118
},
119119

120+
// Use extra babel plugins
121+
babelPlugins: [],
122+
120123
// Extra options from Vue Babel plugin: https://github.com/vuejs/babel-plugin-jsx#options
121124
// ...
122125
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@
6363
},
6464
"dependencies": {
6565
"@babel/core": "^7.28.3",
66-
"@babel/plugin-syntax-typescript": "^7.27.1",
6766
"@vue/babel-plugin-jsx": "^1.5.0",
6867
"unplugin": "^2.3.9"
6968
},
7069
"devDependencies": {
70+
"@babel/plugin-syntax-typescript": "^7.27.1",
7171
"@sxzz/eslint-config": "^7.1.4",
7272
"@sxzz/prettier-config": "^2.2.4",
7373
"@types/babel__core": "^7.20.5",

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/options.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ParserOptions } from '@babel/core'
1+
import type { ParserOptions, PluginItem } from '@babel/core'
22
import type { VueJSXPluginOptions } from '@vue/babel-plugin-jsx'
33
import type { FilterPattern } from 'unplugin'
44

@@ -8,17 +8,19 @@ export type Options = {
88
enforce?: 'pre' | 'post' | undefined
99
sourceMap?: boolean
1010
parserOpts?: ParserOptions
11+
babelPlugins?: PluginItem[]
1112
} & VueJSXPluginOptions
1213

1314
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
1415

1516
export type OptionsResolved = Overwrite<
1617
Options,
17-
Pick<Required<Options>, 'include' | 'exclude' | 'sourceMap'>
18+
Pick<Required<Options>, 'include' | 'exclude' | 'sourceMap' | 'babelPlugins'>
1819
>
1920

2021
export function resolveOptions(options: Options): OptionsResolved {
2122
return {
23+
babelPlugins: [],
2224
...options,
2325
include: options.include || [/\.[jt]sx$/],
2426
exclude: options.exclude || [/node_modules/],

src/core/vue.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { transform, type TransformOptions } from '@babel/core'
2-
// @ts-expect-error
3-
import BabelTS from '@babel/plugin-syntax-typescript'
42
import BabelVueJsx from '@vue/babel-plugin-jsx'
53
import type { OptionsResolved } from './options'
64

@@ -18,7 +16,7 @@ export function transformVueJsx(
1816
const transformOptions: TransformOptions = {
1917
babelrc: false,
2018
configFile: false,
21-
plugins: [[BabelVueJsx, options]],
19+
plugins: [[BabelVueJsx, options], ...options.babelPlugins],
2220
sourceMaps: options.sourceMap,
2321
sourceFileName: id,
2422
parserOpts: {

tests/__snapshots__/basic.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ _createVNode("div", {
1919
}, null);"
2020
`;
2121

22+
exports[`Vue 3 > custom babel plugins 1`] = `
23+
"import { createVNode as _createVNode } from "vue";
24+
const x: string = _createVNode("div", null, null);"
25+
`;
26+
2227
exports[`Vue 3 > custom options 1`] = `
2328
"import { createVNode as _createVNode } from "vue";
2429
_createVNode("input", {

tests/basic.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-expect-error
2+
import BabelTS from '@babel/plugin-syntax-typescript'
13
import { describe, expect, test } from 'vitest'
24
import { resolveOptions, type Options } from '../src/core/options'
35
import { transformVueJsx } from '../src/core/vue'
@@ -31,7 +33,7 @@ describe('Vue 3', () => {
3133
).toMatchSnapshot()
3234
})
3335

34-
test.only('custom parser plugins', () => {
36+
test('custom parser plugins', () => {
3537
expect(
3638
transform(`@x class X {}; const x = <div />`, false, {
3739
parserOpts: {
@@ -48,4 +50,12 @@ describe('Vue 3', () => {
4850
}),
4951
).toMatchSnapshot()
5052
})
53+
54+
test('custom babel plugins', () => {
55+
expect(
56+
transform(`const x: string = <div />`, true, {
57+
babelPlugins: [[BabelTS, { isTSX: true }]],
58+
}),
59+
).toMatchSnapshot()
60+
})
5161
})

0 commit comments

Comments
 (0)