1
1
/* eslint new-cap: 0, callback-return: 0 */
2
2
const acorn = require ( 'acorn' ) ;
3
3
const 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' ;
8
8
9
9
const parser = acorn . Parser . extend (
10
10
privateMethods ,
@@ -13,35 +13,35 @@ const parser = acorn.Parser.extend(
13
13
staticClassFeatures
14
14
) ;
15
15
16
- const noop = ( ) => { } ;
16
+ const noop = ( ) : void => { } ;
17
17
const visitorsWithoutAncestors = {
18
- ClassDeclaration ( node , state , c ) {
18
+ ClassDeclaration ( node , state , c ) : void {
19
19
if ( state . ancestors [ state . ancestors . length - 2 ] === state . body ) {
20
20
state . prepend ( node , `${ node . id . name } =` ) ;
21
21
}
22
22
walk . base . ClassDeclaration ( node , state , c ) ;
23
23
} ,
24
- ForOfStatement ( node , state , c ) {
24
+ ForOfStatement ( node , state , c ) : void {
25
25
if ( node . await === true ) {
26
26
state . containsAwait = true ;
27
27
}
28
28
walk . base . ForOfStatement ( node , state , c ) ;
29
29
} ,
30
- FunctionDeclaration ( node , state , c ) {
30
+ FunctionDeclaration ( node , state ) : void {
31
31
state . prepend ( node , `${ node . id . name } =` ) ;
32
32
} ,
33
33
FunctionExpression : noop ,
34
34
ArrowFunctionExpression : noop ,
35
35
MethodDefinition : noop ,
36
- AwaitExpression ( node , state , c ) {
36
+ AwaitExpression ( node , state , c ) : void {
37
37
state . containsAwait = true ;
38
38
walk . base . AwaitExpression ( node , state , c ) ;
39
39
} ,
40
- ReturnStatement ( node , state , c ) {
40
+ ReturnStatement ( node , state , c ) : void {
41
41
state . containsReturn = true ;
42
42
walk . base . ReturnStatement ( node , state , c ) ;
43
43
} ,
44
- VariableDeclaration ( node , state , c ) {
44
+ VariableDeclaration ( node , state , c ) : void {
45
45
if ( node . kind === 'var' ||
46
46
state . ancestors [ state . ancestors . length - 2 ] === state . body ) {
47
47
if ( node . declarations . length === 1 ) {
@@ -67,7 +67,7 @@ const visitorsWithoutAncestors = {
67
67
const visitors = { } ;
68
68
for ( const nodeType of Object . keys ( walk . base ) ) {
69
69
const callback = visitorsWithoutAncestors [ nodeType ] || walk . base [ nodeType ] ;
70
- visitors [ nodeType ] = ( node , state , c ) => {
70
+ visitors [ nodeType ] = ( node , state , c ) : void => {
71
71
const isNew = node !== state . ancestors [ state . ancestors . length - 1 ] ;
72
72
if ( isNew ) {
73
73
state . ancestors . push ( node ) ;
@@ -79,7 +79,7 @@ for (const nodeType of Object.keys(walk.base)) {
79
79
} ;
80
80
}
81
81
82
- function processTopLevelAwait ( src ) {
82
+ function processTopLevelAwait ( src ) : null | string {
83
83
const wrapped = `(async () => { ${ src } })()` ;
84
84
const wrappedArray = wrapped . split ( '' ) ;
85
85
let root ;
@@ -92,17 +92,17 @@ function processTopLevelAwait(src) {
92
92
const state = {
93
93
body,
94
94
ancestors : [ ] ,
95
- replace ( from , to , str ) {
95
+ replace ( from , to , str ) : void {
96
96
for ( let i = from ; i < to ; i ++ ) {
97
97
wrappedArray [ i ] = '' ;
98
98
}
99
99
if ( from === to ) str += wrappedArray [ from ] ;
100
100
wrappedArray [ from ] = str ;
101
101
} ,
102
- prepend ( node , str ) {
102
+ prepend ( node , str ) : void {
103
103
wrappedArray [ node . start ] = str + wrappedArray [ node . start ] ;
104
104
} ,
105
- append ( node , str ) {
105
+ append ( node , str ) : void {
106
106
wrappedArray [ node . end - 1 ] += str ;
107
107
} ,
108
108
containsAwait : false ,
@@ -139,4 +139,4 @@ function processTopLevelAwait(src) {
139
139
return wrappedArray . join ( '' ) ;
140
140
}
141
141
142
- module . exports = processTopLevelAwait ;
142
+ export default processTopLevelAwait ;
0 commit comments