Skip to content

Commit 34c55ac

Browse files
committed
fix: Fix typescript types for parsing
1 parent 94eefad commit 34c55ac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/babelParser.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
parseSync,
44
ParserOptions,
55
TransformOptions,
6+
ParseResult,
67
} from '@babel/core';
7-
import * as t from '@babel/types';
88
import path from 'path';
99

1010
const TYPESCRIPT_EXTS = {
@@ -46,7 +46,7 @@ function getDefaultPlugins(
4646
}
4747

4848
export type Options = TransformOptions & { parserOptions?: ParserOptions };
49-
export type FileNodeWithOptions = t.File & {
49+
export type FileNodeWithOptions = ParseResult & {
5050
program: { options: Options };
5151
__src: string;
5252
};
@@ -104,7 +104,11 @@ export default function buildParse(options: Options = {}): Parser {
104104

105105
return {
106106
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+
}
108112
// Attach options to the Program node, for use when processing imports.
109113
ast.program.options = options;
110114
return ast;

0 commit comments

Comments
 (0)