@putout/engine-parser 10.2.0 → 10.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/README.md CHANGED
@@ -57,18 +57,22 @@ Print code from `ast`
57
57
 
58
58
  You can add `default options` for custom `parser` you use.
59
59
 
60
- ### parse.fresh(code)
60
+ ### template.fresh(code)
61
61
 
62
62
  `parse` without `memoization`.
63
63
 
64
- ### parse.ast(template)
64
+ ### template.ast(code)
65
65
 
66
66
  create node using `memoization`.
67
67
 
68
- ### parse.ast.fresh(template)
68
+ ### template.ast.fresh(code)
69
69
 
70
70
  create node without `memoization`.
71
71
 
72
+ ### template.extractExpression(code)
73
+
74
+ Extract `expression` node from `ExpressionStatement`.
75
+
72
76
  ### Sourcemaps
73
77
 
74
78
  You have two ways to benefit from source map generation:
package/lib/template.js CHANGED
@@ -14,8 +14,20 @@ const defaults = {
14
14
  ],
15
15
  };
16
16
 
17
- const {isExpressionStatement} = types;
18
- const extractExpression = (a) => isExpressionStatement(a) ? a.expression : a;
17
+ const {
18
+ isExpressionStatement,
19
+ isTSExternalModuleReference,
20
+ } = types;
21
+
22
+ const extractExpression = (a) => {
23
+ if (isExpressionStatement(a))
24
+ return a.expression;
25
+
26
+ if (isTSExternalModuleReference(a))
27
+ return a.expression;
28
+
29
+ return a;
30
+ };
19
31
 
20
32
  module.exports = nanomemoize((value, options) => {
21
33
  const fn = template(value, {
@@ -64,3 +76,5 @@ module.exports.ast.fresh = (value, options) => {
64
76
 
65
77
  return extractExpression(result);
66
78
  };
79
+
80
+ module.exports.extractExpression = extractExpression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-parser",
3
- "version": "10.2.0",
3
+ "version": "10.4.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout parser",
@@ -50,7 +50,7 @@
50
50
  "acorn-jsx": "^5.0.2",
51
51
  "acorn-stage3": "^4.0.0",
52
52
  "c8": "^9.0.0",
53
- "eslint": "^9.0.0-alpha.0",
53
+ "eslint": "^9.0.0",
54
54
  "eslint-plugin-n": "^17.0.0-0",
55
55
  "eslint-plugin-putout": "^22.0.0",
56
56
  "espree": "^10.0.0",