@putout/printer 1.120.0 → 1.121.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/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2023.05.30, v1.121.0
2
+
3
+ feature:
4
+ - 26071a8 @putout/printer: add ability to traverse existing path
5
+
1
6
  2023.05.29, v1.120.0
2
7
 
3
8
  feature:
@@ -91,6 +91,7 @@ module.exports.ObjectProperty = (path, {print, maybe}) => {
91
91
  shorthand,
92
92
  computed,
93
93
  } = path.node;
94
+
94
95
  const properties = path.parentPath.get('properties');
95
96
  const isLast = path === properties.at(-1);
96
97
  const manyLines = !isOneLine(path.parentPath);
@@ -141,4 +142,3 @@ function isParens(path) {
141
142
 
142
143
  return false;
143
144
  }
144
-
@@ -23,7 +23,9 @@ module.exports.VariableDeclaration = {
23
23
  print(path, {maybe, store, write, traverse}) {
24
24
  maybe.indent(isInsideBlock(path));
25
25
  write(String(path.node.kind));
26
- maybeSpaceAfterKeyword(path, {write});
26
+ maybeSpaceAfterKeyword(path, {
27
+ write,
28
+ });
27
29
 
28
30
  const declarations = path.get('declarations');
29
31
  const n = declarations.length - 1;
@@ -150,4 +152,3 @@ const isNextAssign = (path) => {
150
152
  .get('expression')
151
153
  .isAssignmentExpression();
152
154
  };
153
-
@@ -177,12 +177,15 @@ module.exports.tokenize = (ast, overrides = {}) => {
177
177
  ...overrides.visitors,
178
178
  };
179
179
 
180
- babelTraverse(maybeFile(ast), {
181
- Program(path) {
182
- traverse(path);
183
- path.stop();
184
- },
185
- });
180
+ if (ast.parentPath)
181
+ pathTraverse(ast, traverse);
182
+ else
183
+ babelTraverse(maybeFile(ast), {
184
+ Program(path) {
185
+ traverse(path);
186
+ path.stop();
187
+ },
188
+ });
186
189
 
187
190
  function traverse(path) {
188
191
  const {type} = path;
@@ -266,3 +269,14 @@ const computePath = (path, maybeLine) => {
266
269
 
267
270
  return maybeLine;
268
271
  };
272
+
273
+ function pathTraverse(ast, traverse) {
274
+ ast.parentPath.traverse({
275
+ enter(path) {
276
+ if (path === ast) {
277
+ traverse(path);
278
+ path.stop();
279
+ }
280
+ },
281
+ });
282
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.120.0",
3
+ "version": "1.121.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",