@putout/engine-parser 12.2.1 → 12.3.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 -4
- package/lib/parse.js +2 -4
- package/lib/parsers/babel/index.js +16 -1
- package/package.json +1 -1
package/lib/custom-parser.js
CHANGED
|
@@ -13,11 +13,11 @@ const MESSAGES = [
|
|
|
13
13
|
'has already been declared',
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
-
module.exports = (source, parser, {isTS,
|
|
16
|
+
module.exports = (source, parser, {isTS, isJSX, printer}) => {
|
|
17
17
|
const options = {
|
|
18
18
|
parser,
|
|
19
|
+
printer,
|
|
19
20
|
isTS,
|
|
20
|
-
isFlow,
|
|
21
21
|
isJSX,
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -38,13 +38,13 @@ module.exports = (source, parser, {isTS, isFlow, isJSX}) => {
|
|
|
38
38
|
]);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
function customParse(source, {parser,
|
|
41
|
+
function customParse(source, {parser, printer, isTS, isJSX, isRecovery}) {
|
|
42
42
|
if (parser === 'babel')
|
|
43
43
|
return babel.parse(source, {
|
|
44
44
|
isTS,
|
|
45
|
-
isFlow,
|
|
46
45
|
isJSX,
|
|
47
46
|
isRecovery,
|
|
47
|
+
printer,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
if (isObject(parser))
|
package/lib/parse.js
CHANGED
|
@@ -8,7 +8,6 @@ module.exports = (source, options) => {
|
|
|
8
8
|
parser,
|
|
9
9
|
printer = 'putout',
|
|
10
10
|
isTS,
|
|
11
|
-
isFlow,
|
|
12
11
|
isJSX,
|
|
13
12
|
} = options || {};
|
|
14
13
|
|
|
@@ -16,19 +15,18 @@ module.exports = (source, options) => {
|
|
|
16
15
|
printer,
|
|
17
16
|
parser,
|
|
18
17
|
isTS,
|
|
19
|
-
isFlow,
|
|
20
18
|
isJSX,
|
|
21
19
|
});
|
|
22
20
|
|
|
23
21
|
return cookedParser.parse(source);
|
|
24
22
|
};
|
|
25
23
|
|
|
26
|
-
const getParser = ({parser = 'babel', isTS,
|
|
24
|
+
const getParser = ({parser = 'babel', isTS, isJSX, printer}) => ({
|
|
27
25
|
parse(source) {
|
|
28
26
|
const ast = toBabel(customParser(source, parser, {
|
|
29
27
|
isTS,
|
|
30
|
-
isFlow,
|
|
31
28
|
isJSX,
|
|
29
|
+
printer,
|
|
32
30
|
}));
|
|
33
31
|
|
|
34
32
|
return ast;
|
|
@@ -4,11 +4,21 @@ const once = require('once');
|
|
|
4
4
|
|
|
5
5
|
const plugins = require('./plugins');
|
|
6
6
|
const options = require('./options');
|
|
7
|
+
const {assign} = Object;
|
|
7
8
|
const getFlow = (a) => !a.indexOf('// @flow');
|
|
8
9
|
const clean = (a) => a.filter(Boolean);
|
|
9
10
|
const initBabel = once(() => require('@putout/babel'));
|
|
10
11
|
|
|
11
|
-
module.exports.parse = function babelParse(source,
|
|
12
|
+
module.exports.parse = function babelParse(source, overrides) {
|
|
13
|
+
const {
|
|
14
|
+
sourceFileName,
|
|
15
|
+
isTS,
|
|
16
|
+
isJSX = true,
|
|
17
|
+
isFlow = getFlow(source),
|
|
18
|
+
isRecovery,
|
|
19
|
+
printer,
|
|
20
|
+
} = overrides;
|
|
21
|
+
|
|
12
22
|
const {parse} = initBabel();
|
|
13
23
|
const parserOptions = {
|
|
14
24
|
sourceFileName,
|
|
@@ -26,6 +36,11 @@ module.exports.parse = function babelParse(source, {sourceFileName, isTS, isJSX
|
|
|
26
36
|
]),
|
|
27
37
|
};
|
|
28
38
|
|
|
39
|
+
if (printer === 'babel')
|
|
40
|
+
assign(parserOptions, {
|
|
41
|
+
createParenthesizedExpressions: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
29
44
|
return parse(source, parserOptions);
|
|
30
45
|
};
|
|
31
46
|
|