Skip to content

Commit 923d82f

Browse files
authored
fix: sfc error (#27)
1 parent 11795bc commit 923d82f

File tree

8 files changed

+25
-31
lines changed

8 files changed

+25
-31
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Add a \_\_source prop to all Elements.
88

99
- 🌈 Supports `Vue2` and `Vue3`.
1010
- 🪐 Support add to `<Component/>`.
11-
- ✨ JSX support in `.vue`, `.jsx`, `.tsx`.
11+
- ✨ JSX support in `.vue`, `.jsx`, `.tsx`, `.mdx`.
1212
- 😃 Supports `Vite`, `Webpack`, `Rspack`, `Vue CLI`, `Rollup`, `esbuild`.
1313

1414
> For development only
@@ -213,11 +213,6 @@ The following show the default values of the configuration
213213

214214
```ts
215215
export interface Options {
216-
/** @default '**\/*.{vue,jsx,tsx}' */
217-
include?: string | RegExp | (string | RegExp)[];
218-
/** @default 'node_modules/**' */
219-
exclude?: string | RegExp | (string | RegExp)[];
220-
221216
/**
222217
* source root path
223218
*
@@ -230,13 +225,20 @@ export interface Options {
230225
* @default false
231226
*/
232227
sourceMap?: boolean;
233-
234228
/**
235229
* Array containing the plugins that you want to enable.
236230
*
237231
* @default ['jsx', 'typescript']
238232
*/
239233
babelParserPlugins?: ParserPlugin[];
234+
/**
235+
* @default '\/**\/*.{vue,jsx,tsx}'
236+
*/
237+
include?: string | RegExp | (string | RegExp)[];
238+
/**
239+
* @default '\/node_modules\/**\/*'
240+
*/
241+
exclude?: string | RegExp | (string | RegExp)[];
240242
}
241243
```
242244

src/core/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {
3131

3232
function resolveOptions(opts: Options): ResolvedOptions {
3333
return {
34-
include: opts.include ?? '**/*.{vue,jsx,tsx}',
35-
exclude: opts.exclude ?? 'node_modules/**',
3634
root: opts.root ?? process.cwd(),
3735
sourceMap: opts.sourceMap ?? false,
3836
babelParserPlugins: opts.babelParserPlugins ?? [],
37+
include: opts.include ?? '/**/*.{vue,jsx,tsx}',
38+
exclude: opts.exclude ?? '/node_modules/**/*',
3939
};
4040
}
4141

src/core/transform.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { transform_SFC } from './transform_SFC';
77
import { transform_MDX } from './transform_MDX';
88
import { transform_JSX } from './transform_JSX';
99

10-
const skipRE = new RegExp(` ${TRACE_ID}=['"].+:[0-9]+:[0-9]+['"]`);
11-
1210
export function transform(code: string, id: string, opts: ResolvedOptions) {
13-
if (skipRE.test(code)) return;
14-
1511
const { root, sourceMap } = opts;
1612

1713
let s: MagicString;
1814
const parsed = parse_ID(id, root);
1915

16+
if (parsed.query[TRACE_ID]) {
17+
return;
18+
}
19+
2020
if (parsed.isSfc) {
2121
transform_SFC(code, replace, opts);
2222
} else if (parsed.isMdx) {

src/core/transform_JSX.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Position } from '@vue/compiler-dom';
22
import { traverse, types as t } from '@babel/core';
3-
import { parse, ParserPlugin } from '@babel/parser';
3+
import { parse } from '@babel/parser';
44
import { type ResolvedOptions } from '../types';
55

66
export function transform_JSX(
@@ -24,7 +24,7 @@ export function transform_JSX(
2424

2525
const ast = parse(code, {
2626
sourceType: 'unambiguous',
27-
plugins: [...pluginSet] as ParserPlugin[],
27+
plugins: Array.from(pluginSet),
2828
startLine,
2929
// babel start at 0
3030
startColumn: startColumn - 1,

src/types.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { ParserPlugin } from '@babel/parser';
22

33
export interface Options {
4-
/** @default '**\/*.{vue,jsx,tsx}' */
5-
include?: string | RegExp | (string | RegExp)[];
6-
/** @default 'node_modules/**' */
7-
exclude?: string | RegExp | (string | RegExp)[];
8-
94
/**
105
* source root path
116
*
@@ -18,13 +13,20 @@ export interface Options {
1813
* @default false
1914
*/
2015
sourceMap?: boolean;
21-
2216
/**
2317
* Array containing the plugins that you want to enable.
2418
*
2519
* @default ['jsx', 'typescript']
2620
*/
2721
babelParserPlugins?: ParserPlugin[];
22+
/**
23+
* @default '\/**\/*.{vue,jsx,tsx}'
24+
*/
25+
include?: string | RegExp | (string | RegExp)[];
26+
/**
27+
* @default '\/node_modules\/**\/*'
28+
*/
29+
exclude?: string | RegExp | (string | RegExp)[];
2830
}
2931

3032
export type ResolvedOptions = Required<Options>;

test/fixtures/vue-skip/input.vue

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/vue-skip/options.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/fixtures/vue-skip/output.vue

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)