From 13d41831028ba024692ca7f78768739d50e0074d Mon Sep 17 00:00:00 2001 From: jaw <2135326728@qq.com> Date: Mon, 12 Jun 2023 16:42:21 +0800 Subject: [PATCH 1/2] fix: lines break --- src/core/transform.ts | 6 +-- test/transform_filter.test.ts | 75 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 test/transform_filter.test.ts diff --git a/src/core/transform.ts b/src/core/transform.ts index ad3ad31..e2517d7 100644 --- a/src/core/transform.ts +++ b/src/core/transform.ts @@ -6,9 +6,9 @@ import { transformScriptSetup } from './transformScriptSetup' import { transformSfcRefSugar } from './transformSfcRefSugar' import { resolveOptions } from './options' -const scriptSetupRE = // +export const scriptSetupRE = // -export function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean { +export function shouldTransform(code: string, options?: ScriptSetupTransformOptions): boolean { // avoid transforming twice if (code.includes('export default __sfc_main')) return false @@ -16,7 +16,7 @@ export function shouldTransform(code: string, id: string, options?: ScriptSetupT } export async function transform(input: string, id: string, options?: ScriptSetupTransformOptions): Promise { - if (!shouldTransform(input, id, options)) + if (!shouldTransform(input, options)) return null const resolved = resolveOptions(options) if (id.endsWith('.vue') || id.includes('.vue?vue')) diff --git a/test/transform_filter.test.ts b/test/transform_filter.test.ts new file mode 100644 index 0000000..7b45978 --- /dev/null +++ b/test/transform_filter.test.ts @@ -0,0 +1,75 @@ +import { } from 'node:test' +import { describe, expect, it } from 'vitest' +import { scriptSetupRE } from '../src/core' + +describe('transform filter', () => { + describe('look for what needs to be converted by regular ', () => { + const cases: string[] = [ + ``, + ``, + ``, + ` + `, + ` + `, + ` + `, + ``, + ] + + for (const input of cases) { + it(input, () => { + expect(scriptSetupRE.test(input)).toEqual(true) + }) + } + }) + + describe('filter what is not needed by regular ', () => { + const cases: string[] = [ + ` + import HelloWorld from './HelloWorld.vue' + + `, + ``, + ` + `, + ] + + for (const input of cases) { + it(input, () => { + expect(scriptSetupRE.test(input)).toEqual(false) + }) + } + }) +}) From 5d248ea0344cf3447f1d47a68fc0b1a0711632f4 Mon Sep 17 00:00:00 2001 From: jaw <2135326728@qq.com> Date: Mon, 12 Jun 2023 17:28:57 +0800 Subject: [PATCH 2/2] chore: update --- src/core/transform.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/transform.ts b/src/core/transform.ts index e2517d7..06853c5 100644 --- a/src/core/transform.ts +++ b/src/core/transform.ts @@ -8,7 +8,7 @@ import { resolveOptions } from './options' export const scriptSetupRE = // -export function shouldTransform(code: string, options?: ScriptSetupTransformOptions): boolean { +export function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean { // avoid transforming twice if (code.includes('export default __sfc_main')) return false @@ -16,7 +16,7 @@ export function shouldTransform(code: string, options?: ScriptSetupTransformOpti } export async function transform(input: string, id: string, options?: ScriptSetupTransformOptions): Promise { - if (!shouldTransform(input, options)) + if (!shouldTransform(input, id, options)) return null const resolved = resolveOptions(options) if (id.endsWith('.vue') || id.includes('.vue?vue'))