Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit eb5507b

Browse files
committed
fix: avoid transforming twice, close #28
1 parent c5d5608 commit eb5507b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core/transform.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { resolveOptions } from './options'
99
const scriptSetupRE = /<script\s(.*\s)?setup(\s.*)?>/
1010

1111
export function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean {
12+
// avoid transforming twice
13+
if (code.includes('export default __sfc_main'))
14+
return false
1215
return (options?.refTransform && shouldTransformRefSugar(code)) || scriptSetupRE.test(code)
1316
}
1417

test/transform.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ describe('transform', () => {
1919
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
2020

2121
const fixture = await fs.readFile(resolve(root, file), 'utf-8')
22-
expect(transform(fixture, file, { refTransform: true })?.code || fixture).toMatchSnapshot()
22+
const result = transform(fixture, file, { refTransform: true })?.code || fixture
23+
expect(result).toMatchSnapshot()
24+
25+
const result2 = transform(result, file, { refTransform: true })?.code || result
26+
expect(result).toEqual(result2)
2327

2428
warn.mockRestore()
2529
})

0 commit comments

Comments
 (0)