-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (50 loc) · 1.66 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
var babylonToEspree = require("./babylon-to-espree");
var parse = require("babylon").parse;
var tt = require("babylon").tokTypes;
var traverse = require("babel-traverse").default;
var eslintOptions = {};
exports.toEstree = function(ast, code) {
babylonToEspree(ast, traverse, tt, code);
return ast;
};
exports.parse = function (code, options) {
options = options || {};
eslintOptions.ecmaVersion = options.ecmaVersion = options.ecmaVersion || 6;
eslintOptions.sourceType = options.sourceType = options.sourceType || "module";
eslintOptions.allowImportExportEverywhere = options.allowImportExportEverywhere = options.allowImportExportEverywhere || false;
if (options.sourceType === "module") {
eslintOptions.globalReturn = false;
} else {
delete eslintOptions.globalReturn;
}
return exports.parseNoPatch(code, options);
};
exports.parseNoPatch = function (code, options) {
var opts = {
codeFrame: options.hasOwnProperty("codeFrame") ? options.codeFrame : true,
sourceType: options.sourceType,
allowImportExportEverywhere: options.allowImportExportEverywhere, // consistent with espree
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
plugins: [
"flow",
"jsx",
"asyncFunctions",
"asyncGenerators",
"classConstructorCall",
"classProperties",
"decorators",
"doExpressions",
"exponentiationOperator",
"exportExtensions",
"functionBind",
"functionSent",
"objectRestSpread",
"trailingFunctionCommas",
"dynamicImport"
]
};
var ast = parse(code, opts);
exports.toEstree(ast, code);
return ast;
};