8
8
* Licensed under the MIT license.
9
9
* https://github.com/unassert-js/unassert/blob/master/LICENSE
10
10
*/
11
- import { replace , Syntax as syntax } from 'estraverse' ;
11
+ import { replace } from 'estraverse' ;
12
12
13
13
function isLiteral ( node ) {
14
- return node && node . type === syntax . Literal ;
14
+ return node && node . type === ' Literal' ;
15
15
}
16
16
function isIdentifier ( node ) {
17
- return node && node . type === syntax . Identifier ;
17
+ return node && node . type === ' Identifier' ;
18
18
}
19
19
function isObjectPattern ( node ) {
20
- return node && node . type === syntax . ObjectPattern ;
20
+ return node && node . type === ' ObjectPattern' ;
21
21
}
22
22
function isMemberExpression ( node ) {
23
- return node && node . type === syntax . MemberExpression ;
23
+ return node && node . type === ' MemberExpression' ;
24
24
}
25
25
function isCallExpression ( node ) {
26
- return node && node . type === syntax . CallExpression ;
26
+ return node && node . type === ' CallExpression' ;
27
27
}
28
28
function isExpressionStatement ( node ) {
29
- return node && node . type === syntax . ExpressionStatement ;
29
+ return node && node . type === ' ExpressionStatement' ;
30
30
}
31
31
function isIfStatement ( node ) {
32
- return node && node . type === syntax . IfStatement ;
32
+ return node && node . type === ' IfStatement' ;
33
33
}
34
34
function isImportDeclaration ( node ) {
35
- return node && node . type === syntax . ImportDeclaration ;
35
+ return node && node . type === ' ImportDeclaration' ;
36
36
}
37
37
38
38
function isBodyOfNodeHavingNonBlockStatementAsBody ( node , key ) {
@@ -43,13 +43,13 @@ function isBodyOfNodeHavingNonBlockStatementAsBody (node, key) {
43
43
return false ;
44
44
}
45
45
switch ( node . type ) {
46
- case syntax . DoWhileStatement :
47
- case syntax . ForInStatement :
48
- case syntax . ForOfStatement :
49
- case syntax . ForStatement :
50
- case syntax . LabeledStatement :
51
- case syntax . WithStatement :
52
- case syntax . WhileStatement :
46
+ case ' DoWhileStatement' :
47
+ case ' ForInStatement' :
48
+ case ' ForOfStatement' :
49
+ case ' ForStatement' :
50
+ case ' LabeledStatement' :
51
+ case ' WithStatement' :
52
+ case ' WhileStatement' :
53
53
return true ;
54
54
}
55
55
return false ;
@@ -172,7 +172,7 @@ function createVisitor (options) {
172
172
return {
173
173
enter : function ( currentNode , parentNode ) {
174
174
switch ( currentNode . type ) {
175
- case syntax . ImportDeclaration : {
175
+ case ' ImportDeclaration' : {
176
176
const source = currentNode . source ;
177
177
if ( ! ( isAssertionModuleName ( source ) ) ) {
178
178
return ;
@@ -184,7 +184,7 @@ function createVisitor (options) {
184
184
registerAssertionVariables ( currentNode ) ;
185
185
break ;
186
186
}
187
- case syntax . VariableDeclarator : {
187
+ case ' VariableDeclarator' : {
188
188
if ( isRemovalTargetRequire ( currentNode . id , currentNode . init ) ) {
189
189
if ( parentNode . declarations . length === 1 ) {
190
190
// remove parent VariableDeclaration
@@ -200,7 +200,7 @@ function createVisitor (options) {
200
200
}
201
201
break ;
202
202
}
203
- case syntax . AssignmentExpression : {
203
+ case ' AssignmentExpression' : {
204
204
if ( currentNode . operator !== '=' ) {
205
205
return ;
206
206
}
@@ -216,7 +216,7 @@ function createVisitor (options) {
216
216
}
217
217
break ;
218
218
}
219
- case syntax . CallExpression : {
219
+ case ' CallExpression' : {
220
220
if ( ! isExpressionStatement ( parentNode ) ) {
221
221
return ;
222
222
}
@@ -228,7 +228,7 @@ function createVisitor (options) {
228
228
}
229
229
break ;
230
230
}
231
- case syntax . AwaitExpression : {
231
+ case ' AwaitExpression' : {
232
232
const childNode = currentNode . argument ;
233
233
if ( isExpressionStatement ( parentNode ) && isCallExpression ( childNode ) ) {
234
234
const callee = childNode . callee ;
@@ -244,10 +244,10 @@ function createVisitor (options) {
244
244
} ,
245
245
leave : function ( currentNode , parentNode ) {
246
246
switch ( currentNode . type ) {
247
- case syntax . ImportDeclaration :
248
- case syntax . VariableDeclarator :
249
- case syntax . VariableDeclaration :
250
- case syntax . ExpressionStatement :
247
+ case ' ImportDeclaration' :
248
+ case ' VariableDeclarator' :
249
+ case ' VariableDeclaration' :
250
+ case ' ExpressionStatement' :
251
251
break ;
252
252
default :
253
253
return undefined ;
@@ -258,7 +258,7 @@ function createVisitor (options) {
258
258
const key = path [ path . length - 1 ] ;
259
259
if ( isNonBlockChildOfParentNode ( currentNode , parentNode , key ) ) {
260
260
return {
261
- type : syntax . BlockStatement ,
261
+ type : ' BlockStatement' ,
262
262
body : [ ]
263
263
} ;
264
264
}
0 commit comments