Skip to content

Commit b6fc6fa

Browse files
committed
perf!: don't transform TS by default
1 parent eee3fd4 commit b6fc6fa

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/core/vue.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { transform, type TransformOptions } from '@babel/core'
22
// @ts-expect-error
3-
import TS from '@babel/plugin-syntax-typescript'
4-
import vue3Jsx from '@vue/babel-plugin-jsx'
3+
import BabelTS from '@babel/plugin-syntax-typescript'
4+
import BabelVueJsx from '@vue/babel-plugin-jsx'
55
import type { OptionsResolved } from './options'
66

77
function isTS(id: string): boolean {
@@ -13,17 +13,21 @@ export function transformVueJsx(
1313
id: string,
1414
options: Omit<OptionsResolved, 'include' | 'exclude'>,
1515
): { code: string; map: any } | undefined {
16+
const tsSyntax = isTS(id)
17+
1618
const transformOptions: TransformOptions = {
1719
babelrc: false,
1820
configFile: false,
19-
plugins: [[vue3Jsx, options]],
21+
plugins: [[BabelVueJsx, options]],
2022
sourceMaps: options.sourceMap,
2123
sourceFileName: id,
22-
parserOpts: options.parserOpts,
23-
}
24-
25-
if (isTS(id)) {
26-
transformOptions.plugins!.push([TS, { isTSX: true }])
24+
parserOpts: {
25+
...options.parserOpts,
26+
plugins: [
27+
...(tsSyntax ? (['typescript', 'jsx'] as const) : []),
28+
...(options.parserOpts?.plugins || []),
29+
],
30+
},
2731
}
2832

2933
const result = transform(code, transformOptions)

tests/__snapshots__/basic.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ _createVNode("input", _transformOn({
3636
}), null);"
3737
`;
3838

39+
exports[`Vue 3 > custom parser plugins 1`] = `
40+
"import { createVNode as _createVNode } from "vue";
41+
@x
42+
class X {}
43+
;
44+
const x = _createVNode("div", null, null);"
45+
`;
46+
47+
exports[`Vue 3 > custom parser plugins 2`] = `
48+
"import { createVNode as _createVNode } from "vue";
49+
@x
50+
class X {}
51+
;
52+
const x: string = _createVNode("div", null, null);"
53+
`;
54+
3955
exports[`Vue 3 > typescript 1`] = `
4056
"import { createVNode as _createVNode } from "vue";
4157
const foo: any = _createVNode("div", null, null);"

tests/basic.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,22 @@ describe('Vue 3', () => {
3030
}),
3131
).toMatchSnapshot()
3232
})
33+
34+
test.only('custom parser plugins', () => {
35+
expect(
36+
transform(`@x class X {}; const x = <div />`, false, {
37+
parserOpts: {
38+
plugins: ['decorators-legacy'],
39+
},
40+
}),
41+
).toMatchSnapshot()
42+
43+
expect(
44+
transform(`@x class X {}; const x: string = <div />`, true, {
45+
parserOpts: {
46+
plugins: ['decorators-legacy'],
47+
},
48+
}),
49+
).toMatchSnapshot()
50+
})
3351
})

0 commit comments

Comments
 (0)