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