@putout/engine-parser 5.3.3 → 5.4.1

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.
@@ -15,7 +15,7 @@ module.exports.parse = function acornParse(source) {
15
15
  const options = {
16
16
  locations: true,
17
17
  comment: true,
18
- ecmaVersion: 2020,
18
+ ecmaVersion: 2_020,
19
19
  sourceType: 'module',
20
20
  allowAwaitOutsideFunction: true,
21
21
  allowReturnOutsideFunction: true,
@@ -11,7 +11,7 @@ module.exports.parse = function espreeParse(source) {
11
11
  loc: true,
12
12
  tokens: preventUsingEsprima,
13
13
  comment: true,
14
- ecmaVersion: 2020,
14
+ ecmaVersion: 2_020,
15
15
  sourceType: 'module',
16
16
  ecmaFeatures: {
17
17
  jsx: true,
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,30 @@ 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
+ const current = source[i];
58
+
59
+ if (current === '(')
60
+ brackets.pop();
61
+
62
+ return brackets.length;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-parser",
3
- "version": "5.3.3",
3
+ "version": "5.4.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout parser",
@@ -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": "*",