This repository has been archived by the owner on May 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
70 lines (53 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
blockStatement,
callExpression,
expressionStatement,
functionDeclaration,
ifStatement,
variableDeclaration,
returnStatement,
switchStatement,
tryStatement,
forStatement,
} from './lib/core.js';
import * as jsx from './lib/jsx.js';
import * as glimmer from './lib/glimmer-hbs.js';
import * as es6 from './lib/es6.js';
function buildAST(ast, wrapExpression = true) {
// Build the jscodeshift api
let _body = ast && ast.program ? ast.program.body : [];
let _ast = _body.map(node => {
switch(node.type) {
case 'VariableDeclaration':
return variableDeclaration(node);
case 'ExpressionStatement':
return wrapExpression ? expressionStatement(node) : callExpression(node.expression);
case 'IfStatement':
return ifStatement(node);
case 'EmptyStatement':
return 'j.emptyStatement()';
case 'FunctionDeclaration':
return functionDeclaration(node);
case 'ReturnStatement':
return returnStatement(node);
case 'SwitchStatement':
return switchStatement(node);
case 'TryStatement':
return tryStatement(node);
case 'ForStatement':
return forStatement(node);
case 'BlockStatement':
return blockStatement(node);
default:
console.log('buildAST => ', node.type); // eslint-disable-line
return '';
}
});
return _ast;
}
export {
buildAST,
es6,
glimmer,
jsx
}