test('relative ts', () => {
const files = {
'/foo.ts': 'export type P = { foo: number }',
- '/bar.d.ts': 'type X = { bar: string }; export { X as Y }'
+ '/bar.d.ts':
+ 'type X = { bar: string }; export { X as Y };' +
+ // verify that we can parse syntax that is only valid in d.ts
+ 'export const baz: boolean'
}
const { props, deps } = resolve(
`
export function resolveParserPlugins(
lang: string,
- userPlugins?: ParserPlugin[]
+ userPlugins?: ParserPlugin[],
+ dts = false
) {
const plugins: ParserPlugin[] = []
if (lang === 'jsx' || lang === 'tsx') {
userPlugins = userPlugins.filter(p => p !== 'jsx')
}
if (lang === 'ts' || lang === 'tsx') {
- plugins.push('typescript')
+ plugins.push(['typescript', { dts }])
if (!plugins.includes('decorators')) {
plugins.push('decorators-legacy')
}
const ext = extname(filename)
if (ext === '.ts' || ext === '.tsx') {
return babelParse(content, {
- plugins: resolveParserPlugins(ext.slice(1), parserPlugins),
+ plugins: resolveParserPlugins(
+ ext.slice(1),
+ parserPlugins,
+ filename.endsWith('.d.ts')
+ ),
sourceType: 'module'
}).program.body
} else if (ext === '.vue') {