esrap 2.2.1 → 2.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esrap",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Parse in reverse",
5
5
  "repository": {
6
6
  "type": "git",
package/src/context.js CHANGED
@@ -1,4 +1,3 @@
1
- /** @import { TSESTree } from '@typescript-eslint/types' */
2
1
  /** @import { BaseNode, Command, Visitors } from './types' */
3
2
 
4
3
  export const margin = 0;
@@ -51,7 +50,7 @@ export class Context {
51
50
  append(context) {
52
51
  this.#commands.push(context.#commands);
53
52
 
54
- if (this.#has_newline) {
53
+ if (this.#has_newline || context.multiline) {
55
54
  this.multiline = true;
56
55
  }
57
56
  }
@@ -232,6 +232,16 @@ export default (options = {}) => {
232
232
  }
233
233
  }
234
234
 
235
+ /**
236
+ * @param {TSESTree.Node} node
237
+ * @returns {boolean}
238
+ */
239
+ function has_object_or_array_value(node) {
240
+ if (!node || node.type !== 'Property') return false;
241
+ const value = node.value?.type === 'AssignmentPattern' ? node.value.left : node.value;
242
+ return value?.type === 'ObjectExpression' || value?.type === 'ArrayExpression';
243
+ }
244
+
235
245
  /**
236
246
  * @param {Context} context
237
247
  * @param {TSESTree.Node[]} nodes
@@ -280,8 +290,10 @@ export default (options = {}) => {
280
290
  const child = children[i];
281
291
 
282
292
  if (prev !== null) {
283
- if (multiline_nodes[i - 1] || multiline_nodes[i]) {
284
- context.margin();
293
+ if (multiline_nodes[i - 1] && multiline_nodes[i]) {
294
+ if (!has_object_or_array_value(nodes[i - 1]) || !has_object_or_array_value(nodes[i])) {
295
+ context.margin();
296
+ }
285
297
  }
286
298
 
287
299
  if (nodes[i]) {
@@ -35,6 +35,6 @@
35
35
  null,
36
36
  null
37
37
  ],
38
- "mappings": ";MAGYA,QAAQA;;;;;;;;MAQfC,MAAMA;;MAENC,mBAAmBA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