1
- import { type Identifier , type Node , type Options , Parser , tokTypes } from "acorn" ;
1
+ import { Parser , tokTypes } from "acorn" ;
2
+ import type { Expression , Identifier , Node , Options , Program } from "acorn" ;
2
3
import { fileReference } from "./files.js" ;
3
4
import { findAssignments } from "./javascript/assignments.js" ;
4
5
import { findAwaits } from "./javascript/awaits.js" ;
@@ -131,12 +132,12 @@ function parseJavaScript(input: string, options: ParseOptions): JavaScriptNode {
131
132
if ( expression ?. type === "ClassExpression" && expression . id ) expression = null ; // treat named class as program
132
133
if ( expression ?. type === "FunctionExpression" && expression . id ) expression = null ; // treat named function as program
133
134
if ( ! expression && inline ) throw new SyntaxError ( "invalid expression" ) ;
134
- const body = expression ?? ( Parser . parse ( input , parseOptions ) as any ) ;
135
+ const body = expression ?? Parser . parse ( input , parseOptions ) ;
135
136
const exports = findExports ( body ) ;
136
137
if ( exports . length ) throw syntaxError ( "Unexpected token 'export'" , exports [ 0 ] , input ) ; // disallow exports
137
138
const references = findReferences ( body , globals ) ;
138
139
findAssignments ( body , references , globals , input ) ;
139
- const declarations = expression ? null : findDeclarations ( body , globals , input ) ;
140
+ const declarations = expression ? null : findDeclarations ( body as Program , globals , input ) ;
140
141
const imports = findImports ( body , root , sourcePath ) ;
141
142
const features = findFeatures ( body , root , sourcePath , references , input ) ;
142
143
return {
@@ -152,11 +153,11 @@ function parseJavaScript(input: string, options: ParseOptions): JavaScriptNode {
152
153
153
154
// Parses a single expression; like parseExpressionAt, but returns null if
154
155
// additional input follows the expression.
155
- function maybeParseExpression ( input , options ) {
156
+ function maybeParseExpression ( input : string , options : Options ) : Expression | null {
156
157
const parser = new ( Parser as any ) ( options , input , 0 ) ; // private constructor
157
158
parser . nextToken ( ) ;
158
159
try {
159
- const node = ( parser as any ) . parseExpression ( ) ;
160
+ const node = parser . parseExpression ( ) ;
160
161
return parser . type === tokTypes . eof ? node : null ;
161
162
} catch {
162
163
return null ;
0 commit comments