11/* eslint new-cap: 0, callback-return: 0 */
22const acorn = require ( 'acorn' ) ;
33const walk = require ( 'acorn-walk' ) ;
4- const privateMethods = require ( 'acorn-private-methods' ) ;
5- const classFields = require ( 'acorn-class-fields' ) ;
6- const numericSeparator = require ( 'acorn-numeric-separator' ) ;
7- const staticClassFeatures = require ( 'acorn-static-class-features' ) ;
4+ import privateMethods from 'acorn-private-methods' ;
5+ import classFields from 'acorn-class-fields' ;
6+ import numericSeparator from 'acorn-numeric-separator' ;
7+ import staticClassFeatures from 'acorn-static-class-features' ;
88
99const parser = acorn . Parser . extend (
1010 privateMethods ,
@@ -13,35 +13,35 @@ const parser = acorn.Parser.extend(
1313 staticClassFeatures
1414) ;
1515
16- const noop = ( ) => { } ;
16+ const noop = ( ) : void => { } ;
1717const visitorsWithoutAncestors = {
18- ClassDeclaration ( node , state , c ) {
18+ ClassDeclaration ( node , state , c ) : void {
1919 if ( state . ancestors [ state . ancestors . length - 2 ] === state . body ) {
2020 state . prepend ( node , `${ node . id . name } =` ) ;
2121 }
2222 walk . base . ClassDeclaration ( node , state , c ) ;
2323 } ,
24- ForOfStatement ( node , state , c ) {
24+ ForOfStatement ( node , state , c ) : void {
2525 if ( node . await === true ) {
2626 state . containsAwait = true ;
2727 }
2828 walk . base . ForOfStatement ( node , state , c ) ;
2929 } ,
30- FunctionDeclaration ( node , state , c ) {
30+ FunctionDeclaration ( node , state ) : void {
3131 state . prepend ( node , `${ node . id . name } =` ) ;
3232 } ,
3333 FunctionExpression : noop ,
3434 ArrowFunctionExpression : noop ,
3535 MethodDefinition : noop ,
36- AwaitExpression ( node , state , c ) {
36+ AwaitExpression ( node , state , c ) : void {
3737 state . containsAwait = true ;
3838 walk . base . AwaitExpression ( node , state , c ) ;
3939 } ,
40- ReturnStatement ( node , state , c ) {
40+ ReturnStatement ( node , state , c ) : void {
4141 state . containsReturn = true ;
4242 walk . base . ReturnStatement ( node , state , c ) ;
4343 } ,
44- VariableDeclaration ( node , state , c ) {
44+ VariableDeclaration ( node , state , c ) : void {
4545 if ( node . kind === 'var' ||
4646 state . ancestors [ state . ancestors . length - 2 ] === state . body ) {
4747 if ( node . declarations . length === 1 ) {
@@ -67,7 +67,7 @@ const visitorsWithoutAncestors = {
6767const visitors = { } ;
6868for ( const nodeType of Object . keys ( walk . base ) ) {
6969 const callback = visitorsWithoutAncestors [ nodeType ] || walk . base [ nodeType ] ;
70- visitors [ nodeType ] = ( node , state , c ) => {
70+ visitors [ nodeType ] = ( node , state , c ) : void => {
7171 const isNew = node !== state . ancestors [ state . ancestors . length - 1 ] ;
7272 if ( isNew ) {
7373 state . ancestors . push ( node ) ;
@@ -79,7 +79,7 @@ for (const nodeType of Object.keys(walk.base)) {
7979 } ;
8080}
8181
82- function processTopLevelAwait ( src ) {
82+ function processTopLevelAwait ( src ) : null | string {
8383 const wrapped = `(async () => { ${ src } })()` ;
8484 const wrappedArray = wrapped . split ( '' ) ;
8585 let root ;
@@ -92,17 +92,17 @@ function processTopLevelAwait(src) {
9292 const state = {
9393 body,
9494 ancestors : [ ] ,
95- replace ( from , to , str ) {
95+ replace ( from , to , str ) : void {
9696 for ( let i = from ; i < to ; i ++ ) {
9797 wrappedArray [ i ] = '' ;
9898 }
9999 if ( from === to ) str += wrappedArray [ from ] ;
100100 wrappedArray [ from ] = str ;
101101 } ,
102- prepend ( node , str ) {
102+ prepend ( node , str ) : void {
103103 wrappedArray [ node . start ] = str + wrappedArray [ node . start ] ;
104104 } ,
105- append ( node , str ) {
105+ append ( node , str ) : void {
106106 wrappedArray [ node . end - 1 ] += str ;
107107 } ,
108108 containsAwait : false ,
@@ -139,4 +139,4 @@ function processTopLevelAwait(src) {
139139 return wrappedArray . join ( '' ) ;
140140}
141141
142- module . exports = processTopLevelAwait ;
142+ export default processTopLevelAwait ;
0 commit comments