@putout/engine-parser 7.1.0 → 7.2.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.
package/lib/parse.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const recast = require('@putout/recast');
4
4
  const toBabel = require('estree-to-babel');
5
5
  const customParser = require('./custom-parser');
6
+ const moveOutDirectives = require('./recast/move-out-directives');
6
7
 
7
8
  module.exports = (source, options) => {
8
9
  const {
@@ -15,6 +16,7 @@ module.exports = (source, options) => {
15
16
  } = options || {};
16
17
 
17
18
  const cookedParser = getParser({
19
+ printer,
18
20
  parser,
19
21
  isTS,
20
22
  isFlow,
@@ -31,14 +33,19 @@ module.exports = (source, options) => {
31
33
  });
32
34
  };
33
35
 
34
- function getParser({parser = 'babel', isTS, isFlow, isJSX}) {
36
+ function getParser({parser = 'babel', isTS, isFlow, isJSX, printer}) {
35
37
  return {
36
38
  parse(source) {
37
- return toBabel(customParser(source, parser, {
39
+ const ast = toBabel(customParser(source, parser, {
38
40
  isTS,
39
41
  isFlow,
40
42
  isJSX,
41
43
  }));
44
+
45
+ if (printer === 'recast')
46
+ moveOutDirectives(ast);
47
+
48
+ return ast;
42
49
  },
43
50
  };
44
51
  }
@@ -11,7 +11,6 @@ process.env.BABEL_TYPES_8_BREAKING = true;
11
11
 
12
12
  const plugins = require('./plugins');
13
13
  const options = require('./options');
14
- const moveOutDirectives = require('./move-out-directives');
15
14
  const getFlow = (a) => !a.indexOf('// @flow');
16
15
  const clean = (a) => a.filter(Boolean);
17
16
  const initBabel = once(() => require('@babel/parser'));
@@ -42,7 +41,6 @@ module.exports.parse = function babelParse(source, {sourceFilename, isTS, isJSX
42
41
  });
43
42
 
44
43
  const ast = parse(source, parserOptions);
45
- moveOutDirectives(ast);
46
44
 
47
45
  return ast;
48
46
  };
@@ -12,6 +12,8 @@ module.exports = [
12
12
  'destructuringPrivate',
13
13
  'exportDefaultFrom',
14
14
  'throwExpressions',
15
- 'recordAndTuple',
15
+ ['recordAndTuple', {
16
+ syntaxType: 'hash',
17
+ }],
16
18
  'explicitResourceManagement',
17
19
  ];
@@ -5,6 +5,8 @@ const {
5
5
  ExpressionStatement,
6
6
  } = require('@babel/types');
7
7
 
8
+ const {assign} = Object;
9
+
8
10
  module.exports = (ast) => {
9
11
  const {body, directives} = ast.program;
10
12
 
@@ -14,8 +16,13 @@ module.exports = (ast) => {
14
16
  ast.program.directives = [];
15
17
 
16
18
  for (const directive of directives) {
19
+ const {leadingComments} = directive;
17
20
  const {value} = directive.value;
18
- body.unshift(ExpressionStatement(StringLiteral(value)));
21
+ const expression = assign(ExpressionStatement(StringLiteral(value)), {
22
+ leadingComments,
23
+ });
24
+
25
+ body.unshift(expression);
19
26
  }
20
27
 
21
28
  return ast;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-parser",
3
- "version": "7.1.0",
3
+ "version": "7.2.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout parser",
@@ -39,7 +39,7 @@
39
39
  "@babel/types": "^7.19.0",
40
40
  "@putout/printer": "^2.0.0",
41
41
  "@putout/recast": "^1.12.1",
42
- "estree-to-babel": "^5.0.0",
42
+ "estree-to-babel": "^6.0.0",
43
43
  "nano-memoize": "^3.0.11",
44
44
  "once": "^1.4.0",
45
45
  "try-catch": "^3.0.0"