jsc-typescript-ast-mcp 1.1.2 → 1.1.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.
|
@@ -2,7 +2,7 @@ import { Node, SyntaxKind, } from 'ts-morph';
|
|
|
2
2
|
import { analyzeComponent } from './analyzeComponent.js';
|
|
3
3
|
import { getComponent } from './component.js';
|
|
4
4
|
import { getTagName } from './nameHelper.js';
|
|
5
|
-
import { extractOnClickInfoFromNode, extractPropsFromNode } from './props.js';
|
|
5
|
+
import { extractAttributeValueFromNode, extractOnClickInfoFromNode, extractPropsFromNode, } from './props.js';
|
|
6
6
|
import { handleTernary } from './ternary.js';
|
|
7
7
|
export const extractFromExpression = (expression, project, options, depth) => {
|
|
8
8
|
if (Node.isConditionalExpression(expression)) {
|
|
@@ -163,14 +163,14 @@ const buildNodeFromJSX = (node, project, options, depth) => {
|
|
|
163
163
|
treeNode.filePath = localComponentFilePath;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const props = extractPropsFromNode(node);
|
|
166
|
+
const props = extractPropsFromNode(node, options.dataIdAttribute);
|
|
167
167
|
if (props) {
|
|
168
168
|
treeNode.props = props;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
}
|
|
170
|
+
if (options.dataIdAttribute) {
|
|
171
|
+
const dataIdValue = extractAttributeValueFromNode(node, options.dataIdAttribute);
|
|
172
|
+
if (dataIdValue !== undefined && dataIdValue !== null) {
|
|
173
|
+
treeNode.dataId = String(dataIdValue);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
const onClick = extractOnClickInfoFromNode(node);
|
|
@@ -1,4 +1,217 @@
|
|
|
1
1
|
import { Node, } from 'ts-morph';
|
|
2
|
+
const STANDARD_HTML_ATTRIBUTES = new Set([
|
|
3
|
+
'accept',
|
|
4
|
+
'acceptcharset',
|
|
5
|
+
'action',
|
|
6
|
+
'allow',
|
|
7
|
+
'allowfullscreen',
|
|
8
|
+
'alt',
|
|
9
|
+
'as',
|
|
10
|
+
'async',
|
|
11
|
+
'autocapitalize',
|
|
12
|
+
'autocomplete',
|
|
13
|
+
'autocorrect',
|
|
14
|
+
'autofocus',
|
|
15
|
+
'autoplay',
|
|
16
|
+
'capture',
|
|
17
|
+
'cellpadding',
|
|
18
|
+
'cellspacing',
|
|
19
|
+
'charset',
|
|
20
|
+
'challenge',
|
|
21
|
+
'checked',
|
|
22
|
+
'cite',
|
|
23
|
+
'class',
|
|
24
|
+
'classname',
|
|
25
|
+
'cols',
|
|
26
|
+
'colspan',
|
|
27
|
+
'content',
|
|
28
|
+
'contenteditable',
|
|
29
|
+
'controls',
|
|
30
|
+
'coords',
|
|
31
|
+
'crossorigin',
|
|
32
|
+
'data',
|
|
33
|
+
'datetime',
|
|
34
|
+
'decoding',
|
|
35
|
+
'default',
|
|
36
|
+
'defer',
|
|
37
|
+
'dir',
|
|
38
|
+
'dirname',
|
|
39
|
+
'disabled',
|
|
40
|
+
'download',
|
|
41
|
+
'draggable',
|
|
42
|
+
'enctype',
|
|
43
|
+
'fetchpriority',
|
|
44
|
+
'for',
|
|
45
|
+
'form',
|
|
46
|
+
'formaction',
|
|
47
|
+
'formenctype',
|
|
48
|
+
'formmethod',
|
|
49
|
+
'formnovalidate',
|
|
50
|
+
'formtarget',
|
|
51
|
+
'frameborder',
|
|
52
|
+
'headers',
|
|
53
|
+
'height',
|
|
54
|
+
'hidden',
|
|
55
|
+
'high',
|
|
56
|
+
'href',
|
|
57
|
+
'hreflang',
|
|
58
|
+
'htmlfor',
|
|
59
|
+
'httpequiv',
|
|
60
|
+
'id',
|
|
61
|
+
'inputmode',
|
|
62
|
+
'integrity',
|
|
63
|
+
'is',
|
|
64
|
+
'key',
|
|
65
|
+
'kind',
|
|
66
|
+
'label',
|
|
67
|
+
'lang',
|
|
68
|
+
'list',
|
|
69
|
+
'loading',
|
|
70
|
+
'loop',
|
|
71
|
+
'low',
|
|
72
|
+
'max',
|
|
73
|
+
'maxlength',
|
|
74
|
+
'media',
|
|
75
|
+
'method',
|
|
76
|
+
'min',
|
|
77
|
+
'minlength',
|
|
78
|
+
'multiple',
|
|
79
|
+
'muted',
|
|
80
|
+
'name',
|
|
81
|
+
'nomodule',
|
|
82
|
+
'nonce',
|
|
83
|
+
'novalidate',
|
|
84
|
+
'open',
|
|
85
|
+
'optimum',
|
|
86
|
+
'pattern',
|
|
87
|
+
'placeholder',
|
|
88
|
+
'playsinline',
|
|
89
|
+
'poster',
|
|
90
|
+
'preload',
|
|
91
|
+
'readonly',
|
|
92
|
+
'referrerpolicy',
|
|
93
|
+
'rel',
|
|
94
|
+
'required',
|
|
95
|
+
'reversed',
|
|
96
|
+
'role',
|
|
97
|
+
'rows',
|
|
98
|
+
'rowspan',
|
|
99
|
+
'sandbox',
|
|
100
|
+
'scope',
|
|
101
|
+
'selected',
|
|
102
|
+
'shape',
|
|
103
|
+
'size',
|
|
104
|
+
'sizes',
|
|
105
|
+
'slot',
|
|
106
|
+
'span',
|
|
107
|
+
'spellcheck',
|
|
108
|
+
'src',
|
|
109
|
+
'srcdoc',
|
|
110
|
+
'srclang',
|
|
111
|
+
'srcset',
|
|
112
|
+
'start',
|
|
113
|
+
'step',
|
|
114
|
+
'style',
|
|
115
|
+
'tabindex',
|
|
116
|
+
'target',
|
|
117
|
+
'title',
|
|
118
|
+
'translate',
|
|
119
|
+
'type',
|
|
120
|
+
'usemap',
|
|
121
|
+
'value',
|
|
122
|
+
'width',
|
|
123
|
+
'wrap',
|
|
124
|
+
// Common DOM event handler props
|
|
125
|
+
'onabort',
|
|
126
|
+
'onanimationend',
|
|
127
|
+
'onanimationiteration',
|
|
128
|
+
'onanimationstart',
|
|
129
|
+
'onauxclick',
|
|
130
|
+
'onbeforeinput',
|
|
131
|
+
'onblur',
|
|
132
|
+
'oncanplay',
|
|
133
|
+
'oncanplaythrough',
|
|
134
|
+
'onchange',
|
|
135
|
+
'onclick',
|
|
136
|
+
'oncompositionend',
|
|
137
|
+
'oncompositionstart',
|
|
138
|
+
'oncompositionupdate',
|
|
139
|
+
'oncontextmenu',
|
|
140
|
+
'oncopy',
|
|
141
|
+
'oncut',
|
|
142
|
+
'ondblclick',
|
|
143
|
+
'ondrag',
|
|
144
|
+
'ondragend',
|
|
145
|
+
'ondragenter',
|
|
146
|
+
'ondragexit',
|
|
147
|
+
'ondragleave',
|
|
148
|
+
'ondragover',
|
|
149
|
+
'ondragstart',
|
|
150
|
+
'ondrop',
|
|
151
|
+
'ondurationchange',
|
|
152
|
+
'onemptied',
|
|
153
|
+
'onended',
|
|
154
|
+
'onerror',
|
|
155
|
+
'onfocus',
|
|
156
|
+
'onfocusin',
|
|
157
|
+
'onfocusout',
|
|
158
|
+
'onfullscreenchange',
|
|
159
|
+
'onfullscreenerror',
|
|
160
|
+
'ongotpointercapture',
|
|
161
|
+
'oninput',
|
|
162
|
+
'oninvalid',
|
|
163
|
+
'onkeydown',
|
|
164
|
+
'onkeypress',
|
|
165
|
+
'onkeyup',
|
|
166
|
+
'onload',
|
|
167
|
+
'onloadeddata',
|
|
168
|
+
'onloadedmetadata',
|
|
169
|
+
'onloadstart',
|
|
170
|
+
'onlostpointercapture',
|
|
171
|
+
'onmouseenter',
|
|
172
|
+
'onmouseleave',
|
|
173
|
+
'onmousemove',
|
|
174
|
+
'onmouseout',
|
|
175
|
+
'onmouseover',
|
|
176
|
+
'onmouseup',
|
|
177
|
+
'onpaste',
|
|
178
|
+
'onpause',
|
|
179
|
+
'onplay',
|
|
180
|
+
'onplaying',
|
|
181
|
+
'onpointercancel',
|
|
182
|
+
'onpointerdown',
|
|
183
|
+
'onpointerenter',
|
|
184
|
+
'onpointerleave',
|
|
185
|
+
'onpointermove',
|
|
186
|
+
'onpointerout',
|
|
187
|
+
'onpointerover',
|
|
188
|
+
'onpointerup',
|
|
189
|
+
'onprogress',
|
|
190
|
+
'onratechange',
|
|
191
|
+
'onreset',
|
|
192
|
+
'onresize',
|
|
193
|
+
'onscroll',
|
|
194
|
+
'onseeked',
|
|
195
|
+
'onseeking',
|
|
196
|
+
'onselect',
|
|
197
|
+
'onstalled',
|
|
198
|
+
'onsubmit',
|
|
199
|
+
'onsuspend',
|
|
200
|
+
'ontimeupdate',
|
|
201
|
+
'ontoggle',
|
|
202
|
+
'ontransitionend',
|
|
203
|
+
'onvolumechange',
|
|
204
|
+
'onwaiting',
|
|
205
|
+
'onwheel',
|
|
206
|
+
]);
|
|
207
|
+
const isStandardHtmlAttribute = (name) => {
|
|
208
|
+
const normalizedName = name.toLowerCase();
|
|
209
|
+
if (normalizedName.startsWith('aria-') ||
|
|
210
|
+
normalizedName.startsWith('data-')) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return STANDARD_HTML_ATTRIBUTES.has(normalizedName);
|
|
214
|
+
};
|
|
2
215
|
const extractPropValue = (attribute) => {
|
|
3
216
|
const initializer = attribute.getInitializer();
|
|
4
217
|
if (!initializer) {
|
|
@@ -22,7 +235,7 @@ const addSpreadProps = (props, spreadAttribute) => {
|
|
|
22
235
|
// Keep spread attributes as references so callers can resolve them later if needed.
|
|
23
236
|
props[`...${expressionText}`] = expressionText;
|
|
24
237
|
};
|
|
25
|
-
export const extractPropsFromNode = (node) => {
|
|
238
|
+
export const extractPropsFromNode = (node, excludedAttributeName) => {
|
|
26
239
|
const attributes = Node.isJsxElement(node)
|
|
27
240
|
? node.getOpeningElement().getAttributes()
|
|
28
241
|
: node.getAttributes();
|
|
@@ -32,7 +245,13 @@ export const extractPropsFromNode = (node) => {
|
|
|
32
245
|
const props = {};
|
|
33
246
|
for (const attribute of attributes) {
|
|
34
247
|
if (Node.isJsxAttribute(attribute)) {
|
|
35
|
-
|
|
248
|
+
const attributeName = attribute.getNameNode().getText();
|
|
249
|
+
const isExcludedDataIdAttribute = excludedAttributeName !== undefined &&
|
|
250
|
+
attributeName.toLowerCase() === excludedAttributeName.toLowerCase();
|
|
251
|
+
if (isStandardHtmlAttribute(attributeName) || isExcludedDataIdAttribute) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
props[attributeName] = extractPropValue(attribute);
|
|
36
255
|
continue;
|
|
37
256
|
}
|
|
38
257
|
if (Node.isJsxSpreadAttribute(attribute)) {
|
|
@@ -44,6 +263,17 @@ export const extractPropsFromNode = (node) => {
|
|
|
44
263
|
}
|
|
45
264
|
return props;
|
|
46
265
|
};
|
|
266
|
+
export const extractAttributeValueFromNode = (node, attributeName) => {
|
|
267
|
+
const attributes = Node.isJsxElement(node)
|
|
268
|
+
? node.getOpeningElement().getAttributes()
|
|
269
|
+
: node.getAttributes();
|
|
270
|
+
const matchedAttribute = attributes.find((attribute) => Node.isJsxAttribute(attribute) &&
|
|
271
|
+
attribute.getNameNode().getText() === attributeName);
|
|
272
|
+
if (!matchedAttribute || !Node.isJsxAttribute(matchedAttribute)) {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
return extractPropValue(matchedAttribute);
|
|
276
|
+
};
|
|
47
277
|
const getExpressionKind = (expression) => {
|
|
48
278
|
if (Node.isIdentifier(expression)) {
|
|
49
279
|
return 'identifier';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsc-typescript-ast-mcp",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"mcpName": "io.github.jscoobyced/jsc-typescript-ast-mcp",
|
|
5
5
|
"description": "A Model Context Protocol (MCP) server that provides an abstract syntax tree (AST) representation of TypeScript code using the ts-morph library. It allows clients to analyze and manipulate TypeScript code structures, making it easier for AI models to understand and work with TypeScript projects. You can create a JSON representation of your React components, and use it for various purposes such as documentation, code analysis, or even generating new code based on existing components.",
|
|
6
6
|
"main": "dist/index.js",
|