Skip to content

Commit 30d220b

Browse files
authored
Merge pull request #38 from unassert-js/inline-node-types
refactor: inline node types to reduce dependency to estraverse
2 parents c085c44 + 613a84e commit 30d220b

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/index.mjs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88
* Licensed under the MIT license.
99
* https://github.com/unassert-js/unassert/blob/master/LICENSE
1010
*/
11-
import { replace, Syntax as syntax } from 'estraverse';
11+
import { replace } from 'estraverse';
1212

1313
function isLiteral (node) {
14-
return node && node.type === syntax.Literal;
14+
return node && node.type === 'Literal';
1515
}
1616
function isIdentifier (node) {
17-
return node && node.type === syntax.Identifier;
17+
return node && node.type === 'Identifier';
1818
}
1919
function isObjectPattern (node) {
20-
return node && node.type === syntax.ObjectPattern;
20+
return node && node.type === 'ObjectPattern';
2121
}
2222
function isMemberExpression (node) {
23-
return node && node.type === syntax.MemberExpression;
23+
return node && node.type === 'MemberExpression';
2424
}
2525
function isCallExpression (node) {
26-
return node && node.type === syntax.CallExpression;
26+
return node && node.type === 'CallExpression';
2727
}
2828
function isExpressionStatement (node) {
29-
return node && node.type === syntax.ExpressionStatement;
29+
return node && node.type === 'ExpressionStatement';
3030
}
3131
function isIfStatement (node) {
32-
return node && node.type === syntax.IfStatement;
32+
return node && node.type === 'IfStatement';
3333
}
3434
function isImportDeclaration (node) {
35-
return node && node.type === syntax.ImportDeclaration;
35+
return node && node.type === 'ImportDeclaration';
3636
}
3737

3838
function isBodyOfNodeHavingNonBlockStatementAsBody (node, key) {
@@ -43,13 +43,13 @@ function isBodyOfNodeHavingNonBlockStatementAsBody (node, key) {
4343
return false;
4444
}
4545
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':
5353
return true;
5454
}
5555
return false;
@@ -172,7 +172,7 @@ function createVisitor (options) {
172172
return {
173173
enter: function (currentNode, parentNode) {
174174
switch (currentNode.type) {
175-
case syntax.ImportDeclaration: {
175+
case 'ImportDeclaration': {
176176
const source = currentNode.source;
177177
if (!(isAssertionModuleName(source))) {
178178
return;
@@ -184,7 +184,7 @@ function createVisitor (options) {
184184
registerAssertionVariables(currentNode);
185185
break;
186186
}
187-
case syntax.VariableDeclarator: {
187+
case 'VariableDeclarator': {
188188
if (isRemovalTargetRequire(currentNode.id, currentNode.init)) {
189189
if (parentNode.declarations.length === 1) {
190190
// remove parent VariableDeclaration
@@ -200,7 +200,7 @@ function createVisitor (options) {
200200
}
201201
break;
202202
}
203-
case syntax.AssignmentExpression: {
203+
case 'AssignmentExpression': {
204204
if (currentNode.operator !== '=') {
205205
return;
206206
}
@@ -216,7 +216,7 @@ function createVisitor (options) {
216216
}
217217
break;
218218
}
219-
case syntax.CallExpression: {
219+
case 'CallExpression': {
220220
if (!isExpressionStatement(parentNode)) {
221221
return;
222222
}
@@ -228,7 +228,7 @@ function createVisitor (options) {
228228
}
229229
break;
230230
}
231-
case syntax.AwaitExpression: {
231+
case 'AwaitExpression': {
232232
const childNode = currentNode.argument;
233233
if (isExpressionStatement(parentNode) && isCallExpression(childNode)) {
234234
const callee = childNode.callee;
@@ -244,10 +244,10 @@ function createVisitor (options) {
244244
},
245245
leave: function (currentNode, parentNode) {
246246
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':
251251
break;
252252
default:
253253
return undefined;
@@ -258,7 +258,7 @@ function createVisitor (options) {
258258
const key = path[path.length - 1];
259259
if (isNonBlockChildOfParentNode(currentNode, parentNode, key)) {
260260
return {
261-
type: syntax.BlockStatement,
261+
type: 'BlockStatement',
262262
body: []
263263
};
264264
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy