File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 3
3
parseSync ,
4
4
ParserOptions ,
5
5
TransformOptions ,
6
+ ParseResult ,
6
7
} from '@babel/core' ;
7
- import * as t from '@babel/types' ;
8
8
import path from 'path' ;
9
9
10
10
const TYPESCRIPT_EXTS = {
@@ -46,7 +46,7 @@ function getDefaultPlugins(
46
46
}
47
47
48
48
export type Options = TransformOptions & { parserOptions ?: ParserOptions } ;
49
- export type FileNodeWithOptions = t . File & {
49
+ export type FileNodeWithOptions = ParseResult & {
50
50
program : { options : Options } ;
51
51
__src : string ;
52
52
} ;
@@ -104,7 +104,11 @@ export default function buildParse(options: Options = {}): Parser {
104
104
105
105
return {
106
106
parse ( src : string ) : FileNodeWithOptions {
107
- const ast = parseSync ( src , opts ) as FileNodeWithOptions ;
107
+ const ast = parseSync ( src , opts ) as FileNodeWithOptions | null ;
108
+
109
+ if ( ! ast ) {
110
+ throw new Error ( 'Unable to parse source code.' ) ;
111
+ }
108
112
// Attach options to the Program node, for use when processing imports.
109
113
ast . program . options = options ;
110
114
return ast ;
You can’t perform that action at this time.
0 commit comments