@eslint-react/ast 5.30.0-beta.2 → 5.30.0-beta.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 +24 -1
- package/dist/index.js +33 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -211,6 +211,29 @@ declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "
|
|
|
211
211
|
* @returns The fully qualified name.
|
|
212
212
|
*/
|
|
213
213
|
declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
214
|
+
declare namespace analyze_d_exports {
|
|
215
|
+
export { isTerminatingStatement, isUnconditionallyTerminating };
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Check if a statement terminates the control flow of its block.
|
|
219
|
+
*
|
|
220
|
+
* A statement terminates when it cannot complete normally: a `return`, `throw`,
|
|
221
|
+
* `break`, or `continue`, a block containing such a statement, an `if` whose
|
|
222
|
+
* branches both terminate, or a `try` whose paths all terminate. `switch`
|
|
223
|
+
* statements are not analyzed, so a `switch` whose entry paths all terminate is
|
|
224
|
+
* not treated as terminating.
|
|
225
|
+
* @param node The node to check.
|
|
226
|
+
* @returns `true` if the statement terminates the control flow.
|
|
227
|
+
*/
|
|
228
|
+
declare function isTerminatingStatement(node: TSESTree.Node): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Check if every path through a statement exits the current function with a
|
|
231
|
+
* `return` or `throw`. Unlike {@link isTerminatingStatement}, `break` and
|
|
232
|
+
* `continue` are not considered terminating.
|
|
233
|
+
* @param node The node to check.
|
|
234
|
+
* @returns `true` if the statement unconditionally terminates.
|
|
235
|
+
*/
|
|
236
|
+
declare function isUnconditionallyTerminating(node: TSESTree.Node): boolean;
|
|
214
237
|
declare namespace traverse_d_exports {
|
|
215
238
|
export { SimpleTraverseOptions, findEnclosingTryBlock, findParent, hasEnclosingTryBlock, hasParent, simpleTraverse };
|
|
216
239
|
}
|
|
@@ -276,4 +299,4 @@ declare function findEnclosingTryBlock(node: TSESTree.Node): TSESTree.TryStateme
|
|
|
276
299
|
* @returns `true` when an enclosing `try` block exists.
|
|
277
300
|
*/
|
|
278
301
|
declare function hasEnclosingTryBlock(node: TSESTree.Node): boolean;
|
|
279
|
-
export { check_d_exports as Check, collect_d_exports as Collect, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeFunctionOrClass, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, type TSESTreeTypeOrChainExpression, traverse_d_exports as Traverse };
|
|
302
|
+
export { analyze_d_exports as Analyze, check_d_exports as Check, collect_d_exports as Collect, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeFunctionOrClass, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, type TSESTreeTypeOrChainExpression, traverse_d_exports as Traverse };
|
package/dist/index.js
CHANGED
|
@@ -564,4 +564,36 @@ function getReturnExpressions(node) {
|
|
|
564
564
|
if (node.body.type !== AST_NODE_TYPES.BlockStatement) return [node.body];
|
|
565
565
|
return getReturnStatements(node).flatMap((stmt) => stmt.argument == null ? [] : [stmt.argument]);
|
|
566
566
|
}
|
|
567
|
-
|
|
567
|
+
// src/analyze.ts
|
|
568
|
+
var analyze_exports = /* @__PURE__ */ __exportAll({
|
|
569
|
+
isTerminatingStatement: () => isTerminatingStatement,
|
|
570
|
+
isUnconditionallyTerminating: () => isUnconditionallyTerminating
|
|
571
|
+
});
|
|
572
|
+
function isTerminatingStatement(node) {
|
|
573
|
+
switch (node.type) {
|
|
574
|
+
case AST_NODE_TYPES.ReturnStatement:
|
|
575
|
+
case AST_NODE_TYPES.ThrowStatement:
|
|
576
|
+
case AST_NODE_TYPES.BreakStatement:
|
|
577
|
+
case AST_NODE_TYPES.ContinueStatement: return true;
|
|
578
|
+
case AST_NODE_TYPES.BlockStatement: return node.body.some(isTerminatingStatement);
|
|
579
|
+
case AST_NODE_TYPES.IfStatement: return node.alternate != null && isTerminatingStatement(node.consequent) && isTerminatingStatement(node.alternate);
|
|
580
|
+
case AST_NODE_TYPES.TryStatement:
|
|
581
|
+
if (node.finalizer != null && isTerminatingStatement(node.finalizer)) return true;
|
|
582
|
+
if (node.handler == null) return isTerminatingStatement(node.block);
|
|
583
|
+
return isTerminatingStatement(node.block) && isTerminatingStatement(node.handler.body);
|
|
584
|
+
default: return false;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function isUnconditionallyTerminating(node) {
|
|
588
|
+
switch (node.type) {
|
|
589
|
+
case AST_NODE_TYPES.ReturnStatement:
|
|
590
|
+
case AST_NODE_TYPES.ThrowStatement: return true;
|
|
591
|
+
case AST_NODE_TYPES.BlockStatement: {
|
|
592
|
+
const last = node.body.at(-1);
|
|
593
|
+
return last != null && isUnconditionallyTerminating(last);
|
|
594
|
+
}
|
|
595
|
+
case AST_NODE_TYPES.IfStatement: return node.alternate != null && isUnconditionallyTerminating(node.consequent) && isUnconditionallyTerminating(node.alternate);
|
|
596
|
+
default: return false;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
export { analyze_exports as Analyze, check_exports as Check, collect_exports as Collect, compare_exports as Compare, extract_exports as Extract, traverse_exports as Traverse };
|