Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add a \_\_source prop to all Elements.

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

> For development only
Expand Down Expand Up @@ -213,11 +213,6 @@ The following show the default values of the configuration

```ts
export interface Options {
/** @default '**\/*.{vue,jsx,tsx}' */
include?: string | RegExp | (string | RegExp)[];
/** @default 'node_modules/**' */
exclude?: string | RegExp | (string | RegExp)[];

/**
* source root path
*
Expand All @@ -230,13 +225,20 @@ export interface Options {
* @default false
*/
sourceMap?: boolean;

/**
* Array containing the plugins that you want to enable.
*
* @default ['jsx', 'typescript']
*/
babelParserPlugins?: ParserPlugin[];
/**
* @default '\/**\/*.{vue,jsx,tsx}'
*/
include?: string | RegExp | (string | RegExp)[];
/**
* @default '\/node_modules\/**\/*'
*/
exclude?: string | RegExp | (string | RegExp)[];
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {

function resolveOptions(opts: Options): ResolvedOptions {
return {
include: opts.include ?? '**/*.{vue,jsx,tsx}',
exclude: opts.exclude ?? 'node_modules/**',
root: opts.root ?? process.cwd(),
sourceMap: opts.sourceMap ?? false,
babelParserPlugins: opts.babelParserPlugins ?? [],
include: opts.include ?? '/**/*.{vue,jsx,tsx}',
exclude: opts.exclude ?? '/node_modules/**/*',
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { transform_SFC } from './transform_SFC';
import { transform_MDX } from './transform_MDX';
import { transform_JSX } from './transform_JSX';

const skipRE = new RegExp(` ${TRACE_ID}=['"].+:[0-9]+:[0-9]+['"]`);

export function transform(code: string, id: string, opts: ResolvedOptions) {
if (skipRE.test(code)) return;

const { root, sourceMap } = opts;

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

if (parsed.query[TRACE_ID]) {
return;
}

if (parsed.isSfc) {
transform_SFC(code, replace, opts);
} else if (parsed.isMdx) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/transform_JSX.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Position } from '@vue/compiler-dom';
import { traverse, types as t } from '@babel/core';
import { parse, ParserPlugin } from '@babel/parser';
import { parse } from '@babel/parser';
import { type ResolvedOptions } from '../types';

export function transform_JSX(
Expand All @@ -24,7 +24,7 @@ export function transform_JSX(

const ast = parse(code, {
sourceType: 'unambiguous',
plugins: [...pluginSet] as ParserPlugin[],
plugins: Array.from(pluginSet),
startLine,
// babel start at 0
startColumn: startColumn - 1,
Expand Down
14 changes: 8 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ParserPlugin } from '@babel/parser';

export interface Options {
/** @default '**\/*.{vue,jsx,tsx}' */
include?: string | RegExp | (string | RegExp)[];
/** @default 'node_modules/**' */
exclude?: string | RegExp | (string | RegExp)[];

/**
* source root path
*
Expand All @@ -18,13 +13,20 @@ export interface Options {
* @default false
*/
sourceMap?: boolean;

/**
* Array containing the plugins that you want to enable.
*
* @default ['jsx', 'typescript']
*/
babelParserPlugins?: ParserPlugin[];
/**
* @default '\/**\/*.{vue,jsx,tsx}'
*/
include?: string | RegExp | (string | RegExp)[];
/**
* @default '\/node_modules\/**\/*'
*/
exclude?: string | RegExp | (string | RegExp)[];
}

export type ResolvedOptions = Required<Options>;
3 changes: 0 additions & 3 deletions test/fixtures/vue-skip/input.vue

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/vue-skip/options.ts

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/vue-skip/output.vue

This file was deleted.