File tree 3 files changed +12
-4
lines changed
3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -458,7 +458,10 @@ describe('resolveType', () => {
458
458
test ( 'relative ts' , ( ) => {
459
459
const files = {
460
460
'/foo.ts' : 'export type P = { foo: number }' ,
461
- '/bar.d.ts' : 'type X = { bar: string }; export { X as Y }'
461
+ '/bar.d.ts' :
462
+ 'type X = { bar: string }; export { X as Y };' +
463
+ // verify that we can parse syntax that is only valid in d.ts
464
+ 'export const baz: boolean'
462
465
}
463
466
const { props, deps } = resolve (
464
467
`
Original file line number Diff line number Diff line change @@ -145,7 +145,8 @@ export class ScriptCompileContext {
145
145
146
146
export function resolveParserPlugins (
147
147
lang : string ,
148
- userPlugins ?: ParserPlugin [ ]
148
+ userPlugins ?: ParserPlugin [ ] ,
149
+ dts = false
149
150
) {
150
151
const plugins : ParserPlugin [ ] = [ ]
151
152
if ( lang === 'jsx' || lang === 'tsx' ) {
@@ -156,7 +157,7 @@ export function resolveParserPlugins(
156
157
userPlugins = userPlugins . filter ( p => p !== 'jsx' )
157
158
}
158
159
if ( lang === 'ts' || lang === 'tsx' ) {
159
- plugins . push ( 'typescript' )
160
+ plugins . push ( [ 'typescript' , { dts } ] )
160
161
if ( ! plugins . includes ( 'decorators' ) ) {
161
162
plugins . push ( 'decorators-legacy' )
162
163
}
Original file line number Diff line number Diff line change @@ -933,7 +933,11 @@ function parseFile(
933
933
const ext = extname ( filename )
934
934
if ( ext === '.ts' || ext === '.tsx' ) {
935
935
return babelParse ( content , {
936
- plugins : resolveParserPlugins ( ext . slice ( 1 ) , parserPlugins ) ,
936
+ plugins : resolveParserPlugins (
937
+ ext . slice ( 1 ) ,
938
+ parserPlugins ,
939
+ filename . endsWith ( '.d.ts' )
940
+ ) ,
937
941
sourceType : 'module'
938
942
} ) . program . body
939
943
} else if ( ext === '.vue' ) {
You can’t perform that action at this time.
0 commit comments