File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -458,7 +458,10 @@ describe('resolveType', () => {
458458 test ( 'relative ts' , ( ) => {
459459 const files = {
460460 '/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'
462465 }
463466 const { props, deps } = resolve (
464467 `
Original file line number Diff line number Diff line change @@ -145,7 +145,8 @@ export class ScriptCompileContext {
145145
146146export function resolveParserPlugins (
147147 lang : string ,
148- userPlugins ?: ParserPlugin [ ]
148+ userPlugins ?: ParserPlugin [ ] ,
149+ dts = false
149150) {
150151 const plugins : ParserPlugin [ ] = [ ]
151152 if ( lang === 'jsx' || lang === 'tsx' ) {
@@ -156,7 +157,7 @@ export function resolveParserPlugins(
156157 userPlugins = userPlugins . filter ( p => p !== 'jsx' )
157158 }
158159 if ( lang === 'ts' || lang === 'tsx' ) {
159- plugins . push ( 'typescript' )
160+ plugins . push ( [ 'typescript' , { dts } ] )
160161 if ( ! plugins . includes ( 'decorators' ) ) {
161162 plugins . push ( 'decorators-legacy' )
162163 }
Original file line number Diff line number Diff line change @@ -933,7 +933,11 @@ function parseFile(
933933 const ext = extname ( filename )
934934 if ( ext === '.ts' || ext === '.tsx' ) {
935935 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+ ) ,
937941 sourceType : 'module'
938942 } ) . program . body
939943 } else if ( ext === '.vue' ) {
You can’t perform that action at this time.
0 commit comments