esrap 2.2.0 → 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.0",
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]) {
@@ -1,10 +1,11 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
+ import { BaseNode } from '../types';
2
3
 
3
4
  export type TSOptions = {
4
5
  quotes?: 'double' | 'single';
5
6
  comments?: Comment[];
6
- getLeadingComments?: (node: TSESTree.Node) => BaseComment[] | undefined;
7
- getTrailingComments?: (node: TSESTree.Node) => BaseComment[] | undefined;
7
+ getLeadingComments?: (node: BaseNode) => BaseComment[] | undefined;
8
+ getTrailingComments?: (node: BaseNode) => BaseComment[] | undefined;
8
9
  };
9
10
 
10
11
  interface Position {
package/types/index.d.ts CHANGED
@@ -77,8 +77,8 @@ declare module 'esrap/languages/ts' {
77
77
  type TSOptions = {
78
78
  quotes?: 'double' | 'single';
79
79
  comments?: Comment[];
80
- getLeadingComments?: (node: TSESTree.Node) => BaseComment[] | undefined;
81
- getTrailingComments?: (node: TSESTree.Node) => BaseComment[] | undefined;
80
+ getLeadingComments?: (node: BaseNode) => BaseComment[] | undefined;
81
+ getTrailingComments?: (node: BaseNode) => BaseComment[] | undefined;
82
82
  };
83
83
 
84
84
  interface Position {
@@ -132,8 +132,8 @@ declare module 'esrap/languages/tsx' {
132
132
  type TSOptions = {
133
133
  quotes?: 'double' | 'single';
134
134
  comments?: Comment[];
135
- getLeadingComments?: (node: TSESTree.Node) => BaseComment[] | undefined;
136
- getTrailingComments?: (node: TSESTree.Node) => BaseComment[] | undefined;
135
+ getLeadingComments?: (node: BaseNode) => BaseComment[] | undefined;
136
+ getTrailingComments?: (node: BaseNode) => BaseComment[] | undefined;
137
137
  };
138
138
 
139
139
  interface Position {
@@ -35,6 +35,6 @@
35
35
  null,
36
36
  null
37
37
  ],
38
- "mappings": ";MAGYA,QAAQA;;;;;;;;MAQfC,MAAMA;;MAENC,mBAAmBA;;;;MAIZC,OAAOA;;aAEPC,QAAQA;;;;WAwBHC,QAAQA;;;;;;MAWbC,OAAOA;;kBAEFC,YAAYA;;;;;;;;;iBCHbC,KAAKA;;;;cC5CRC,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCDPC,sBAAsBA;;aAHZC,IAAIA;MCHfC,SAASA;;;;;;;WAOXC,QAAQA;;;;;;;kBAODC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