jsc-typescript-ast-mcp 1.1.3 → 1.1.5
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.
|
@@ -163,7 +163,7 @@ 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
169
|
}
|
|
@@ -212,6 +212,8 @@ const isStandardHtmlAttribute = (name) => {
|
|
|
212
212
|
}
|
|
213
213
|
return STANDARD_HTML_ATTRIBUTES.has(normalizedName);
|
|
214
214
|
};
|
|
215
|
+
const normalizeAttributeName = (name) => name.replace(/[-_]/g, '').toLowerCase();
|
|
216
|
+
const matchesAttributeName = (name, target) => normalizeAttributeName(name) === normalizeAttributeName(target);
|
|
215
217
|
const extractPropValue = (attribute) => {
|
|
216
218
|
const initializer = attribute.getInitializer();
|
|
217
219
|
if (!initializer) {
|
|
@@ -235,7 +237,7 @@ const addSpreadProps = (props, spreadAttribute) => {
|
|
|
235
237
|
// Keep spread attributes as references so callers can resolve them later if needed.
|
|
236
238
|
props[`...${expressionText}`] = expressionText;
|
|
237
239
|
};
|
|
238
|
-
export const extractPropsFromNode = (node) => {
|
|
240
|
+
export const extractPropsFromNode = (node, excludedAttributeName) => {
|
|
239
241
|
const attributes = Node.isJsxElement(node)
|
|
240
242
|
? node.getOpeningElement().getAttributes()
|
|
241
243
|
: node.getAttributes();
|
|
@@ -246,7 +248,9 @@ export const extractPropsFromNode = (node) => {
|
|
|
246
248
|
for (const attribute of attributes) {
|
|
247
249
|
if (Node.isJsxAttribute(attribute)) {
|
|
248
250
|
const attributeName = attribute.getNameNode().getText();
|
|
249
|
-
|
|
251
|
+
const isExcludedDataIdAttribute = excludedAttributeName !== undefined &&
|
|
252
|
+
matchesAttributeName(attributeName, excludedAttributeName);
|
|
253
|
+
if (isStandardHtmlAttribute(attributeName) || isExcludedDataIdAttribute) {
|
|
250
254
|
continue;
|
|
251
255
|
}
|
|
252
256
|
props[attributeName] = extractPropValue(attribute);
|
|
@@ -266,7 +270,7 @@ export const extractAttributeValueFromNode = (node, attributeName) => {
|
|
|
266
270
|
? node.getOpeningElement().getAttributes()
|
|
267
271
|
: node.getAttributes();
|
|
268
272
|
const matchedAttribute = attributes.find((attribute) => Node.isJsxAttribute(attribute) &&
|
|
269
|
-
attribute.getNameNode().getText()
|
|
273
|
+
matchesAttributeName(attribute.getNameNode().getText(), attributeName));
|
|
270
274
|
if (!matchedAttribute || !Node.isJsxAttribute(matchedAttribute)) {
|
|
271
275
|
return undefined;
|
|
272
276
|
}
|
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.5",
|
|
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",
|