Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix tests
  • Loading branch information
tobiasdiez committed Oct 13, 2023
commit 434cce1a79e18bc907a872683af5bfb2ab75ab5a
14 changes: 7 additions & 7 deletions src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import { ParsedMeta, ParsedStory, parse } from './parser'
export async function transform(code: string) {
let result = ''
const { resolvedScript, meta, stories, docs } = parse(code)
const isTS = resolvedScript?.lang === 'ts'
if (resolvedScript) {
const isTS = resolvedScript.lang === 'ts'
const plugins: ParserPlugin[] = isTS ? ['typescript'] : []
result += rewriteDefault(resolvedScript.content, '_sfc_main', plugins)
const babelPlugins: ParserPlugin[] = isTS ? ['typescript'] : []
result += rewriteDefault(resolvedScript.content, '_sfc_main', babelPlugins)
result += '\n'
} else {
result += 'const _sfc_main = {}\n'
}
result += await transformTemplate({ meta, stories, docs }, resolvedScript)
result = organizeImports(result)
result = await organizeImports(result, isTS)
return result

/*
Expand Down Expand Up @@ -151,10 +151,10 @@ function generateStoryImport(
};`
}

function organizeImports(result: string): string {
async function organizeImports(result: string, isTS: boolean): Promise<string> {
// Use prettier to organize imports
return prettierFormat(result, {
parser: 'babel',
return await prettierFormat(result, {
parser: isTS ? 'typescript' : 'babel',
plugins: ['prettier-plugin-organize-imports'],
})
}
10 changes: 5 additions & 5 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ describe('transform', () => {
p: \\"p\\",
},
_provideComponents(),
props.components
props.components,
);
return _jsxs(_Fragment, {
children: [
Expand All @@ -343,14 +343,14 @@ describe('transform', () => {
const { wrapper: MDXLayout } = Object.assign(
{},
_provideComponents(),
props.components
props.components,
);
return MDXLayout
? _jsx(
MDXLayout,
Object.assign({}, props, {
children: _jsx(_createMdxContent, props),
})
}),
)
: _createMdxContent(props);
}
Expand Down Expand Up @@ -464,7 +464,7 @@ describe('transform', () => {
_createElementVNode(\\"h1\\", null, _toDisplayString($setup.headingText)),
_createElementVNode(\\"p\\", null, _toDisplayString($setup.paragraph)),
],
64 /* STABLE_FRAGMENT */
64 /* STABLE_FRAGMENT */,
)
);
}
Expand All @@ -491,7 +491,7 @@ describe('transform', () => {
_createElementVNode(\\"h1\\", null, _toDisplayString($setup.headingText)),
_createElementVNode(\\"p\\", null, _toDisplayString($setup.paragraph)),
],
64 /* STABLE_FRAGMENT */
64 /* STABLE_FRAGMENT */,
)
);
}
Expand Down