@putout/engine-parser 4.10.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/custom-parser.js +4 -0
- package/lib/parsers/babel/index.js +9 -3
- package/lib/parsers/hermes.js +21 -0
- package/package.json +7 -6
package/lib/custom-parser.js
CHANGED
|
@@ -5,6 +5,7 @@ const babel = require('./parsers/babel');
|
|
|
5
5
|
const espree = require('./parsers/espree');
|
|
6
6
|
const esprima = require('./parsers/esprima');
|
|
7
7
|
const tenko = require('./parsers/tenko');
|
|
8
|
+
const hermes = require('./parsers/hermes');
|
|
8
9
|
const secondChance = require('./second-chance');
|
|
9
10
|
|
|
10
11
|
const isObject = (a) => typeof a === 'object';
|
|
@@ -49,6 +50,9 @@ function customParse(source, {parser, isTS, isFlow, isJSX}) {
|
|
|
49
50
|
if (parser === 'tenko')
|
|
50
51
|
return tenko.parse(source);
|
|
51
52
|
|
|
53
|
+
if (parser === 'hermes')
|
|
54
|
+
return hermes.parse(source);
|
|
55
|
+
|
|
52
56
|
return require(parser).parse(source);
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {assign} = Object;
|
|
4
|
+
|
|
3
5
|
const once = require('once');
|
|
4
6
|
|
|
5
7
|
// stricter validation to prevent even more invalid ASTs: not only
|
|
@@ -23,11 +25,9 @@ const moveOutDirectives = require('./move-out-directives');
|
|
|
23
25
|
// babel, putout: sourceFilename
|
|
24
26
|
module.exports.parse = function babelParse(source, {sourceFilename, isTS, isJSX = true, isFlow = getFlow(source)}) {
|
|
25
27
|
const {parse} = initBabel();
|
|
26
|
-
|
|
27
|
-
const ast = parse(source, {
|
|
28
|
+
const parserOptions = {
|
|
28
29
|
sourceType: 'module',
|
|
29
30
|
tokens: true,
|
|
30
|
-
sourceFilename,
|
|
31
31
|
...options,
|
|
32
32
|
plugins: clean([
|
|
33
33
|
...plugins,
|
|
@@ -37,8 +37,14 @@ module.exports.parse = function babelParse(source, {sourceFilename, isTS, isJSX
|
|
|
37
37
|
isJSX,
|
|
38
38
|
}),
|
|
39
39
|
]),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
sourceFilename && assign(parserOptions, {
|
|
43
|
+
sourceFilename,
|
|
40
44
|
});
|
|
41
45
|
|
|
46
|
+
const ast = parse(source, parserOptions);
|
|
47
|
+
|
|
42
48
|
moveOutDirectives(ast);
|
|
43
49
|
|
|
44
50
|
return ast;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const once = require('once');
|
|
4
|
+
|
|
5
|
+
const initHermes = once(() => require('hermes-parser'));
|
|
6
|
+
|
|
7
|
+
module.exports.parse = function hermesParse(source) {
|
|
8
|
+
const parser = initHermes();
|
|
9
|
+
const options = {
|
|
10
|
+
babel: true,
|
|
11
|
+
allowReturnOutsideFunction: true,
|
|
12
|
+
flow: 'detect',
|
|
13
|
+
locations: true,
|
|
14
|
+
tokens: true,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const result = parser.parse(source, options);
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "putout parser",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@babel/template": "^7.10.4",
|
|
39
39
|
"@babel/types": "^7.12.6",
|
|
40
40
|
"@putout/recast": "^1.1.0",
|
|
41
|
-
"estree-to-babel": "^
|
|
41
|
+
"estree-to-babel": "^5.0.0",
|
|
42
42
|
"nano-memoize": "^1.1.8",
|
|
43
43
|
"once": "^1.4.0",
|
|
44
44
|
"try-catch": "^3.0.0"
|
|
@@ -55,21 +55,22 @@
|
|
|
55
55
|
"c8": "^7.5.0",
|
|
56
56
|
"eslint": "^8.0.1",
|
|
57
57
|
"eslint-plugin-node": "^11.0.0",
|
|
58
|
-
"eslint-plugin-putout": "^
|
|
58
|
+
"eslint-plugin-putout": "^14.0.0",
|
|
59
59
|
"espree": "^9.0.0",
|
|
60
60
|
"esprima": "^4.0.1",
|
|
61
|
+
"hermes-parser": "^0.5.0",
|
|
61
62
|
"just-camel-case": "^4.0.2",
|
|
62
63
|
"lerna": "^4.0.0",
|
|
63
|
-
"madrun": "^
|
|
64
|
+
"madrun": "^9.0.0",
|
|
64
65
|
"montag": "^1.0.0",
|
|
65
66
|
"nodemon": "^2.0.1",
|
|
66
67
|
"putout": "*",
|
|
67
|
-
"supertape": "^
|
|
68
|
+
"supertape": "^7.0.0",
|
|
68
69
|
"tenko": "^2.0.0"
|
|
69
70
|
},
|
|
70
71
|
"license": "MIT",
|
|
71
72
|
"engines": {
|
|
72
|
-
"node": ">=
|
|
73
|
+
"node": ">=16"
|
|
73
74
|
},
|
|
74
75
|
"publishConfig": {
|
|
75
76
|
"access": "public"
|