@putout/engine-parser 5.3.2 → 5.4.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/parsers/acorn.js +1 -1
- package/lib/parsers/espree.js +1 -1
- package/lib/print.js +35 -5
- package/package.json +3 -2
package/lib/parsers/acorn.js
CHANGED
package/lib/parsers/espree.js
CHANGED
package/lib/print.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {print} = require('@putout/recast');
|
|
4
|
-
|
|
4
|
+
const generate = require('@babel/generator').default;
|
|
5
5
|
const fixStrictMode = (a) => a.replace(`\n\n\n'use strict'`, `\n\n'use strict'`);
|
|
6
6
|
const btoa = (a) => Buffer.from(a, 'binary').toString('base64');
|
|
7
7
|
const addSourceMap = (sourceMapName, {code, map}) => !sourceMapName ? code : `${code}\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(stringify(map))}\n`;
|
|
8
|
-
|
|
9
8
|
const {stringify} = JSON;
|
|
10
|
-
|
|
9
|
+
const {assign} = Object;
|
|
11
10
|
module.exports = (ast, options = {}) => {
|
|
12
11
|
const {sourceMapName} = options;
|
|
13
12
|
const printOptions = {
|
|
@@ -16,8 +15,17 @@ module.exports = (ast, options = {}) => {
|
|
|
16
15
|
wrapColumn: Infinity,
|
|
17
16
|
...options,
|
|
18
17
|
};
|
|
19
|
-
|
|
20
18
|
const printed = print(ast, printOptions);
|
|
19
|
+
|
|
20
|
+
if (checkBrackets(printed.code))
|
|
21
|
+
assign(printed, {
|
|
22
|
+
code: generate(ast, {
|
|
23
|
+
indent: {
|
|
24
|
+
style: ' ',
|
|
25
|
+
},
|
|
26
|
+
}).code,
|
|
27
|
+
});
|
|
28
|
+
|
|
21
29
|
const {map} = printed;
|
|
22
30
|
const code = fixStrictMode(printed.code);
|
|
23
31
|
|
|
@@ -26,4 +34,26 @@ module.exports = (ast, options = {}) => {
|
|
|
26
34
|
map,
|
|
27
35
|
});
|
|
28
36
|
};
|
|
29
|
-
|
|
37
|
+
function checkBrackets(source) {
|
|
38
|
+
const brackets = [];
|
|
39
|
+
let i = source.length;
|
|
40
|
+
|
|
41
|
+
if (!i)
|
|
42
|
+
return false;
|
|
43
|
+
|
|
44
|
+
while (--i) {
|
|
45
|
+
const current = source[i];
|
|
46
|
+
|
|
47
|
+
if (current === ')') {
|
|
48
|
+
brackets.push(current);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (current === '(') {
|
|
53
|
+
brackets.pop();
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return brackets.length;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-parser",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.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/parser": "^7.19.0",
|
|
39
39
|
"@babel/template": "^7.18.10",
|
|
40
40
|
"@babel/types": "^7.19.0",
|
|
41
|
-
"@putout/recast": "^1.1
|
|
41
|
+
"@putout/recast": "^1.12.1",
|
|
42
42
|
"estree-to-babel": "^5.0.0",
|
|
43
43
|
"nano-memoize": "^2.0.0",
|
|
44
44
|
"once": "^1.4.0",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"just-camel-case": "^4.0.2",
|
|
63
63
|
"lerna": "^6.0.1",
|
|
64
64
|
"madrun": "^9.0.0",
|
|
65
|
+
"mock-require": "^3.0.3",
|
|
65
66
|
"montag": "^1.0.0",
|
|
66
67
|
"nodemon": "^2.0.1",
|
|
67
68
|
"putout": "*",
|