1+ // Add "namespace", "module" and "name" properties to Typescript nodes that have a globalFqn property
2+
3+ MATCH (ts :TS )
4+ WHERE ts .globalFqn IS NOT NULL
5+ WITH ts
6+ ,replace (split (ts .globalFqn , '".' )[0 ],'"' , '' ) AS moduleName
7+ ,replace (split (ts .globalFqn , '/index' )[0 ],'"' , '' ) AS moduleNameWithoutIndex
8+ ,split (ts .globalFqn , '".' )[1 ] AS symbolName
9+ ,split (nullif (reverse (split (reverse (ts .globalFqn ), '@' )[0 ]), ts .globalFqn ), '/' )[0 ] AS namespaceName
10+ ,(ts .globalFqn contains '/node_modules/' ) AS isNodeModule
11+ ,((NOT ts .globalFqn STARTS WITH '/' ) AND size (split (ts .globalFqn , '/' )) < 3 ) AS isUnresolvedImport
12+ WITH *
13+ ,reverse (split (reverse (moduleNameWithoutIndex ), '/' )[0 ]) AS indexedName
14+ ,coalesce ('@' + nullif (namespaceName , '' ), '' ) AS namespaceNameWithAtPrefixed
15+ SET ts .namespace = namespaceNameWithAtPrefixed
16+ ,ts .module = moduleName
17+ ,ts .name = coalesce (symbolName , indexedName )
18+ ,ts .isNodeModule = isNodeModule
19+ ,ts .isUnresolvedImport = isUnresolvedImport
20+ ,ts .isExternalImport = isNodeModule OR isUnresolvedImport
21+ RETURN count (* ) AS updatedModules
0 commit comments