@react-analyzer/ast 0.0.2-next.0 → 0.0.2-next.1
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 +26 -1
- package/dist/index.js +93 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { AST } from 'tsl';
|
|
2
|
+
import { SyntaxKind } from 'typescript';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
declare function toStringFormat(node: AST.AnyNode): string;
|
|
8
|
+
|
|
9
|
+
declare function is<T extends AST.AnyNode>(kind: T["kind"]): (node: AST.AnyNode) => node is T;
|
|
10
|
+
declare function isOneOf<T extends AST.AnyNode>(kinds: T["kind"][]): (node: AST.AnyNode) => node is T;
|
|
11
|
+
declare const isFunction: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
12
|
+
declare const isClass: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
13
|
+
declare const isMethodOrProperty: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
14
|
+
declare const isLoop: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
15
|
+
declare const isControlFlow: (data: AST.AnyNode) => data is AST.AnyNode;
|
|
16
|
+
declare const isMemberExpressionStrict: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
17
|
+
declare function isLogicalExpression(node: AST.AnyNode): node is AST.BinaryExpression & {
|
|
18
|
+
operatorToken: {
|
|
19
|
+
kind: SyntaxKind.AmpersandAmpersandToken;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
3
22
|
declare function isLogicalNegationExpression(node: AST.AnyNode): node is AST.PrefixUnaryExpression;
|
|
23
|
+
declare const isProperty: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
24
|
+
declare const isJSXElement: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
25
|
+
declare const isJSXFragment: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
26
|
+
declare const isJSX: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
27
|
+
declare const isTypeExpression: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
28
|
+
declare const isTypeAssertionExpressionLoose: (node: AST.AnyNode) => node is AST.AnyNode;
|
|
4
29
|
|
|
5
|
-
export { isLogicalNegationExpression };
|
|
30
|
+
export { is, isClass, isControlFlow, isFunction, isJSX, isJSXElement, isJSXFragment, isLogicalExpression, isLogicalNegationExpression, isLoop, isMemberExpressionStrict, isMethodOrProperty, isOneOf, isProperty, isTypeAssertionExpressionLoose, isTypeExpression, toStringFormat };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,99 @@
|
|
|
1
|
+
import 'string-ts';
|
|
2
|
+
import { or } from '@react-analyzer/eff';
|
|
1
3
|
import { SyntaxKind } from 'typescript';
|
|
2
4
|
|
|
3
|
-
// src/
|
|
5
|
+
// src/ast-node-format.ts
|
|
6
|
+
function is(kind) {
|
|
7
|
+
return (node) => node.kind === kind;
|
|
8
|
+
}
|
|
9
|
+
function isOneOf(kinds) {
|
|
10
|
+
return (node) => kinds.includes(node.kind);
|
|
11
|
+
}
|
|
12
|
+
var isFunction = isOneOf([
|
|
13
|
+
SyntaxKind.ArrowFunction,
|
|
14
|
+
SyntaxKind.FunctionDeclaration,
|
|
15
|
+
SyntaxKind.FunctionExpression
|
|
16
|
+
]);
|
|
17
|
+
var isClass = isOneOf([SyntaxKind.ClassDeclaration, SyntaxKind.ClassExpression]);
|
|
18
|
+
var isMethodOrProperty = isOneOf([
|
|
19
|
+
SyntaxKind.PropertyDeclaration,
|
|
20
|
+
SyntaxKind.MethodDeclaration
|
|
21
|
+
]);
|
|
22
|
+
var isLoop = isOneOf([
|
|
23
|
+
SyntaxKind.DoStatement,
|
|
24
|
+
SyntaxKind.ForInStatement,
|
|
25
|
+
SyntaxKind.ForOfStatement,
|
|
26
|
+
SyntaxKind.ForStatement,
|
|
27
|
+
SyntaxKind.WhileStatement
|
|
28
|
+
]);
|
|
29
|
+
var isControlFlow = or(
|
|
30
|
+
isLoop,
|
|
31
|
+
isOneOf([
|
|
32
|
+
SyntaxKind.IfStatement,
|
|
33
|
+
SyntaxKind.SwitchStatement
|
|
34
|
+
])
|
|
35
|
+
);
|
|
36
|
+
var isMemberExpressionStrict = isOneOf([
|
|
37
|
+
SyntaxKind.PropertyAccessExpression,
|
|
38
|
+
SyntaxKind.ElementAccessExpression
|
|
39
|
+
]);
|
|
40
|
+
function isLogicalExpression(node) {
|
|
41
|
+
return node.kind === SyntaxKind.BinaryExpression && node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken;
|
|
42
|
+
}
|
|
4
43
|
function isLogicalNegationExpression(node) {
|
|
5
44
|
return node.kind === SyntaxKind.PrefixUnaryExpression && node.operator === SyntaxKind.ExclamationToken;
|
|
6
45
|
}
|
|
46
|
+
var isProperty = isOneOf([
|
|
47
|
+
SyntaxKind.PropertyDeclaration,
|
|
48
|
+
SyntaxKind.IndexSignature,
|
|
49
|
+
SyntaxKind.Parameter,
|
|
50
|
+
SyntaxKind.PropertySignature
|
|
51
|
+
]);
|
|
52
|
+
var isJSXElement = is(SyntaxKind.JsxElement);
|
|
53
|
+
var isJSXFragment = is(SyntaxKind.JsxFragment);
|
|
54
|
+
var isJSX = isOneOf([
|
|
55
|
+
// SyntaxKind.JsxIdentifier,
|
|
56
|
+
// SyntaxKind.JsxMemberExpression,
|
|
57
|
+
SyntaxKind.JsxAttribute,
|
|
58
|
+
SyntaxKind.JsxAttributes,
|
|
59
|
+
SyntaxKind.JsxClosingElement,
|
|
60
|
+
SyntaxKind.JsxClosingFragment,
|
|
61
|
+
SyntaxKind.JsxElement,
|
|
62
|
+
SyntaxKind.JsxExpression,
|
|
63
|
+
SyntaxKind.JsxFragment,
|
|
64
|
+
SyntaxKind.JsxNamespacedName,
|
|
65
|
+
SyntaxKind.JsxOpeningElement,
|
|
66
|
+
SyntaxKind.JsxOpeningFragment,
|
|
67
|
+
SyntaxKind.JsxSelfClosingElement,
|
|
68
|
+
SyntaxKind.JsxSpreadAttribute,
|
|
69
|
+
SyntaxKind.JsxText
|
|
70
|
+
]);
|
|
71
|
+
var isTypeExpression = isOneOf([
|
|
72
|
+
SyntaxKind.AsExpression,
|
|
73
|
+
SyntaxKind.TypeAssertionExpression,
|
|
74
|
+
SyntaxKind.NonNullExpression,
|
|
75
|
+
SyntaxKind.SatisfiesExpression,
|
|
76
|
+
SyntaxKind.ExpressionWithTypeArguments
|
|
77
|
+
]);
|
|
78
|
+
var isTypeAssertionExpressionLoose = isOneOf([
|
|
79
|
+
SyntaxKind.AsExpression,
|
|
80
|
+
SyntaxKind.TypeAssertionExpression,
|
|
81
|
+
SyntaxKind.NonNullExpression,
|
|
82
|
+
SyntaxKind.SatisfiesExpression
|
|
83
|
+
]);
|
|
84
|
+
function toStringFormat(node) {
|
|
85
|
+
switch (node.kind) {
|
|
86
|
+
case SyntaxKind.JsxText:
|
|
87
|
+
case SyntaxKind.Identifier:
|
|
88
|
+
case SyntaxKind.PrivateIdentifier:
|
|
89
|
+
return node.text;
|
|
90
|
+
case SyntaxKind.PropertyAccessExpression:
|
|
91
|
+
return `${toStringFormat(node.expression)}.${toStringFormat(node.name)}`;
|
|
92
|
+
case SyntaxKind.JsxNamespacedName:
|
|
93
|
+
return `${node.namespace.text}:${node.name.text}`;
|
|
94
|
+
default:
|
|
95
|
+
return node.getText();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
7
98
|
|
|
8
|
-
export { isLogicalNegationExpression };
|
|
99
|
+
export { is, isClass, isControlFlow, isFunction, isJSX, isJSXElement, isJSXFragment, isLogicalExpression, isLogicalNegationExpression, isLoop, isMemberExpressionStrict, isMethodOrProperty, isOneOf, isProperty, isTypeAssertionExpressionLoose, isTypeExpression, toStringFormat };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-analyzer/ast",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.1",
|
|
4
4
|
"description": "React Analyzer TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/react-analyzer",
|
|
6
6
|
"bugs": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"string-ts": "^2.2.1",
|
|
31
31
|
"ts-pattern": "^5.7.1",
|
|
32
|
-
"@react-analyzer/eff": "0.0.2-next.
|
|
32
|
+
"@react-analyzer/eff": "0.0.2-next.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsup": "^8.5.0",
|