@@ -1422,10 +1422,9 @@ static char *pxc_import_value_qn(CBMLanguage lang, const CBMFileResult *result,
14221422/* JS/TS barrels. An import that lands on a Folder (`./svc` -> svc/index.ts)
14231423 * or on a module that only re-exports the name never reaches the declaring
14241424 * module, so `module.Name` is not in the registry and DI member calls on the
1425- * imported type stay unresolved. Follow the barrel's own IMPORTS edges (its
1426- * `export ... from` statements) to the one module that defines `name`. Those
1427- * edges do not record which names each statement re-exports, so the
1428- * definition node is the proof; two different definitions fail closed. */
1425+ * imported type stay unresolved. Follow only the barrel's re-export IMPORTS
1426+ * edges, preserving `export { original as public }` names across each hop.
1427+ * The definition node is the proof; two different definitions fail closed. */
14291428enum { PXC_BARREL_MAX_DEPTH = 8 };
14301429
14311430static bool pxc_is_js_family (CBMLanguage lang ) {
@@ -1445,6 +1444,30 @@ static char *pxc_defined_symbol_qn(const cbm_gbuf_t *gbuf, const char *project_n
14451444 return NULL ;
14461445}
14471446
1447+ static bool pxc_edge_string_prop (const char * json , const char * key , char * out , size_t out_sz ) {
1448+ if (!json || !key || !out || out_sz == 0 ) {
1449+ return false;
1450+ }
1451+ char needle [CBM_SZ_64 ];
1452+ int wrote = snprintf (needle , sizeof (needle ), "\"%s\":\"" , key );
1453+ if (wrote <= 0 || (size_t )wrote >= sizeof (needle )) {
1454+ return false;
1455+ }
1456+ const char * start = strstr (json , needle );
1457+ if (!start ) {
1458+ return false;
1459+ }
1460+ start += (size_t )wrote ;
1461+ const char * end = strchr (start , '"' );
1462+ size_t len = end ? (size_t )(end - start ) : 0 ;
1463+ if (!end || len == 0 || len >= out_sz || memchr (start , '\\' , len )) {
1464+ return false;
1465+ }
1466+ memcpy (out , start , len );
1467+ out [len ] = '\0' ;
1468+ return true;
1469+ }
1470+
14481471/* `visited` holds barrel file QNs already searched for `name`: barrels form
14491472 * DAGs (and cycles) where one lib index is reachable through many paths, and
14501473 * re-walking it on each path is exponential in the depth cap. */
@@ -1454,6 +1477,13 @@ static char *pxc_barrel_symbol_qn(const cbm_gbuf_t *gbuf, const char *project_na
14541477 if (!target || !target -> label || !target -> file_path || depth > PXC_BARREL_MAX_DEPTH ) {
14551478 return NULL ;
14561479 }
1480+ if (strcmp (target -> label , "Module" ) != 0 && strcmp (target -> label , "Folder" ) != 0 &&
1481+ strcmp (target -> label , "File" ) != 0 ) {
1482+ /* A named re-export edge reaches a definition directly when ordinary
1483+ * import resolution proved its imported member. The edge metadata has
1484+ * already matched the public/imported names at the caller above. */
1485+ return target -> qualified_name ? strdup (target -> qualified_name ) : NULL ;
1486+ }
14571487 static const char * const index_names [] = {"index.ts" , "index.tsx" , "index.mts" ,
14581488 "index.js" , "index.jsx" , "index.mjs" };
14591489 char rel [CBM_SZ_1K ];
@@ -1488,8 +1518,27 @@ static char *pxc_barrel_symbol_qn(const cbm_gbuf_t *gbuf, const char *project_na
14881518 }
14891519 char * found = NULL ;
14901520 for (int i = 0 ; i < edge_count ; i ++ ) {
1521+ char kind [CBM_SZ_16 ];
1522+ char public_name [CBM_SZ_256 ];
1523+ char imported_name [CBM_SZ_256 ];
1524+ if (!pxc_edge_string_prop (edges [i ]-> properties_json , "reexport" , kind , sizeof (kind ))) {
1525+ continue ;
1526+ }
1527+ const char * next_name = name ;
1528+ if (strcmp (kind , "named" ) == 0 ) {
1529+ if (!pxc_edge_string_prop (edges [i ]-> properties_json , "local_name" , public_name ,
1530+ sizeof (public_name )) ||
1531+ strcmp (public_name , name ) != 0 ||
1532+ !pxc_edge_string_prop (edges [i ]-> properties_json , "imported" , imported_name ,
1533+ sizeof (imported_name ))) {
1534+ continue ;
1535+ }
1536+ next_name = imported_name ;
1537+ } else if (strcmp (kind , "star" ) != 0 ) {
1538+ continue ;
1539+ }
14911540 const cbm_gbuf_node_t * next = cbm_gbuf_find_by_id (gbuf , edges [i ]-> target_id );
1492- char * qn = pxc_barrel_symbol_qn (gbuf , project_name , next , name , depth + 1 , visited );
1541+ char * qn = pxc_barrel_symbol_qn (gbuf , project_name , next , next_name , depth + 1 , visited );
14931542 if (!qn ) {
14941543 continue ;
14951544 }
0 commit comments