@@ -61,7 +61,7 @@ const transformJSX = (
6161 const line = loc . start . line
6262 const column = loc . start . column
6363
64- // Check if props are spread and element name starts with lowercase
64+ // Check if props are spread
6565 const hasSpread = element . node . attributes . some (
6666 ( attr ) =>
6767 attr . type === 'JSXSpreadAttribute' &&
@@ -70,31 +70,54 @@ const transformJSX = (
7070 )
7171
7272 if ( hasSpread ) {
73- // Do not inject if props are spread and element is lowercase (native HTML)
73+ // Do not inject if props are spread
7474 return
7575 }
76- if ( propsName ) {
77- // inject data-source either via props or default to a string "<file>:<line>:<column>"
78- // Inject data-source via props
79- element . node . attributes . push (
80- t . jsxAttribute (
81- t . jsxIdentifier ( 'data-tsd-source' ) ,
82- t . jsxExpressionContainer (
83- t . logicalExpression (
84- '??' ,
85- t . memberExpression (
86- t . identifier ( propsName ) ,
87- t . stringLiteral ( 'data-tsd-source' ) ,
88- true ,
76+
77+ /* const isLowercase = element.node.name.type === "JSXIdentifier" ? element.node.name.name.charAt(0) === element.node.name.name.charAt(0).toLowerCase() : false
78+ // Check if the JSX element is imported from a third-party library
79+ let externalImport = false;
80+ if (element.node.name.type === "JSXIdentifier") {
81+ const jsxName = element.node.name.name;
82+ const program = element.findParent((p) => p.isProgram());
83+ if (program && program.node.type === "Program") {
84+ const importDecl = program.node.body.find(
85+ (stmt) =>
86+ stmt.type === "ImportDeclaration" &&
87+ stmt.specifiers.some(
88+ (spec) =>
89+ (spec.type === "ImportSpecifier" || spec.type === "ImportDefaultSpecifier" ) &&
90+ spec.local.name === jsxName
91+ ) &&
92+ !stmt.source.value.startsWith(".") // not a relative import
93+ && !stmt.source.value.startsWith("@/")
94+ && !stmt.source.value.startsWith("~")
95+ );
96+ externalImport = !!importDecl;
97+ }
98+ }
99+ if (propsName && !(externalImport)) {
100+ // inject data-source either via props or default to a string "<file>:<line>:<column>"
101+ // Inject data-source via props
102+ element.node.attributes.push(
103+ t.jsxAttribute(
104+ t.jsxIdentifier('data-tsd-source'),
105+ t.jsxExpressionContainer(
106+ t.logicalExpression(
107+ '??',
108+ t.memberExpression(
109+ t.identifier(propsName),
110+ t.stringLiteral('data-tsd-source'),
111+ true,
112+ ),
113+ t.stringLiteral(`${file}:${line}:${column}`),
89114 ),
90- t . stringLiteral ( `${ file } :${ line } :${ column } ` ) ,
91115 ),
92116 ),
93- ) ,
94- )
95-
96- return true
97- }
117+ )
118+
119+ return true
120+ } */
98121
99122 // Inject data-source as a string: "<file>:<line>:<column>"
100123 element . node . attributes . push (
0 commit comments