@eslint-react/ast 2.8.2-next.2 → 2.8.2-next.4

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/dist/index.d.ts CHANGED
@@ -125,6 +125,22 @@ declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallEx
125
125
  */
126
126
  declare function getFileDirectives(node: TSESTree.Program): TSESTree.StringLiteral[];
127
127
  //#endregion
128
+ //#region src/format.d.ts
129
+ /**
130
+ * Convert a node type to a delimiter format string
131
+ * @param node The AST node
132
+ * @param delimiter The delimiter to use
133
+ * @returns The delimiter format string
134
+ */
135
+ declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
136
+ /**
137
+ * Incomplete but sufficient stringification of AST nodes for common use cases
138
+ * @param node The AST node
139
+ * @param getText A function to get the text representation of a node
140
+ * @returns A string representation of the node
141
+ */
142
+ declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
143
+ //#endregion
128
144
  //#region src/function-directive.d.ts
129
145
  /**
130
146
  * Get all directive string literals from a function node
@@ -224,33 +240,19 @@ declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTre
224
240
  declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
225
241
  declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
226
242
  //#endregion
227
- //#region src/misc.d.ts
243
+ //#region src/location.d.ts
228
244
  /**
229
- * Check if a node is multiline
245
+ * Check if a node spans multiple lines
230
246
  * @param node The AST node to check
231
- * @returns `true` if the node is multiline
247
+ * @returns `true` if the node spans multiple lines, `false` otherwise
232
248
  */
233
249
  declare function isMultiLine(node: TSESTree.Node): boolean;
234
250
  /**
235
- * Check if a node is a line break
251
+ * Check if a node is a line break (whitespace spanning multiple lines)
236
252
  * @param node The AST node to check
237
- * @returns boolean
253
+ * @returns `true` if the node is a line break, `false` otherwise
238
254
  */
239
255
  declare function isLineBreak(node: TSESTree.Node): boolean;
240
- /**
241
- * Convert a node type to a delimiter format string
242
- * @param node The AST node
243
- * @param delimiter The delimiter to use
244
- * @returns The delimiter format string
245
- */
246
- declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
247
- /**
248
- * Incomplete but sufficient stringification of AST nodes for common use cases
249
- * @param node The AST node
250
- * @param getText A function to get the text representation of a node
251
- * @returns A string representation of the node
252
- */
253
- declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
254
256
  //#endregion
255
257
  //#region src/process-env-node-env.d.ts
256
258
  /**
package/dist/index.js CHANGED
@@ -418,6 +418,43 @@ function getFileDirectives(node) {
418
418
  return directives;
419
419
  }
420
420
 
421
+ //#endregion
422
+ //#region src/format.ts
423
+ /**
424
+ * Convert a node type to a delimiter format string
425
+ * @param node The AST node
426
+ * @param delimiter The delimiter to use
427
+ * @returns The delimiter format string
428
+ */
429
+ function toDelimiterFormat(node, delimiter = " ") {
430
+ if (node.type === AST_NODE_TYPES.Literal) {
431
+ if ("regex" in node) return "RegExp literal";
432
+ if (node.value === null) return "null literal";
433
+ return `${typeof node.value} literal`;
434
+ }
435
+ if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
436
+ return toLowerCase(delimiterCase(node.type, delimiter));
437
+ }
438
+ /**
439
+ * Incomplete but sufficient stringification of AST nodes for common use cases
440
+ * @param node The AST node
441
+ * @param getText A function to get the text representation of a node
442
+ * @returns A string representation of the node
443
+ */
444
+ function toStringFormat(node, getText) {
445
+ switch (node.type) {
446
+ case AST_NODE_TYPES.Identifier:
447
+ case AST_NODE_TYPES.JSXIdentifier:
448
+ case AST_NODE_TYPES.PrivateIdentifier: return node.name;
449
+ case AST_NODE_TYPES.MemberExpression:
450
+ case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
451
+ case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
452
+ case AST_NODE_TYPES.JSXText: return node.value;
453
+ case AST_NODE_TYPES.Literal: return node.raw;
454
+ default: return getText(node);
455
+ }
456
+ }
457
+
421
458
  //#endregion
422
459
  //#region src/function-directive.ts
423
460
  /**
@@ -568,65 +605,23 @@ function isIdentifierName(name) {
568
605
  }
569
606
 
570
607
  //#endregion
571
- //#region src/misc.ts
608
+ //#region src/location.ts
572
609
  /**
573
- * Check if a node is multiline
610
+ * Check if a node spans multiple lines
574
611
  * @param node The AST node to check
575
- * @returns `true` if the node is multiline
612
+ * @returns `true` if the node spans multiple lines, `false` otherwise
576
613
  */
577
614
  function isMultiLine(node) {
578
615
  return node.loc.start.line !== node.loc.end.line;
579
616
  }
580
617
  /**
581
- * Check if a node is a line break
618
+ * Check if a node is a line break (whitespace spanning multiple lines)
582
619
  * @param node The AST node to check
583
- * @returns boolean
620
+ * @returns `true` if the node is a line break, `false` otherwise
584
621
  */
585
622
  function isLineBreak(node) {
586
623
  return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
587
624
  }
588
- /**
589
- * Get the type of a literal value
590
- * @param input The literal value
591
- * @returns The type of the literal value
592
- */
593
- function getLiteralValueType(input) {
594
- if (input === null) return "null";
595
- return typeof input;
596
- }
597
- /**
598
- * Convert a node type to a delimiter format string
599
- * @param node The AST node
600
- * @param delimiter The delimiter to use
601
- * @returns The delimiter format string
602
- */
603
- function toDelimiterFormat(node, delimiter = " ") {
604
- if (node.type === AST_NODE_TYPES.Literal) {
605
- if ("regex" in node) return "RegExp literal";
606
- return `${getLiteralValueType(node.value)} literal`;
607
- }
608
- if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
609
- return toLowerCase(delimiterCase(node.type, delimiter));
610
- }
611
- /**
612
- * Incomplete but sufficient stringification of AST nodes for common use cases
613
- * @param node The AST node
614
- * @param getText A function to get the text representation of a node
615
- * @returns A string representation of the node
616
- */
617
- function toStringFormat(node, getText) {
618
- switch (node.type) {
619
- case AST_NODE_TYPES.Identifier:
620
- case AST_NODE_TYPES.JSXIdentifier:
621
- case AST_NODE_TYPES.PrivateIdentifier: return node.name;
622
- case AST_NODE_TYPES.MemberExpression:
623
- case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
624
- case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
625
- case AST_NODE_TYPES.JSXText: return node.value;
626
- case AST_NODE_TYPES.Literal: return node.raw;
627
- default: return getText(node);
628
- }
629
- }
630
625
 
631
626
  //#endregion
632
627
  //#region src/process-env-node-env.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "2.8.2-next.2",
3
+ "version": "2.8.2-next.4",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,7 +34,7 @@
34
34
  "@typescript-eslint/typescript-estree": "^8.54.0",
35
35
  "@typescript-eslint/utils": "^8.54.0",
36
36
  "string-ts": "^2.3.1",
37
- "@eslint-react/eff": "2.8.2-next.2"
37
+ "@eslint-react/eff": "2.8.2-next.4"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsdown": "^0.20.1",