|
1 | | -// Add "namespace", "module" and "name" properties to Typescript nodes that have a globalFqn property |
2 | | - |
| 1 | +// Add extended properties to Typescript nodes with a globalFqn like "namespace", "module", "name" and "extension" as well as markers like "isNodeModule", "isUnresolvedImport" and "isExternalImport" |
3 | 2 | MATCH (ts:TS) |
4 | 3 | WHERE ts.globalFqn IS NOT NULL |
| 4 | +OPTIONAL MATCH (class:TS:Class)-[:DECLARES]->(ts) |
5 | 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 |
| 6 | + ,replace(split(ts.globalFqn, '".')[0],'"', '') AS modulePathName |
| 7 | + ,reverse(split(reverse(replace(split(ts.globalFqn, '".')[0],'"', '')), '/')[0]) AS moduleName |
| 8 | + ,replace(split(split(ts.globalFqn, '/index')[0], '.default')[0],'"', '') AS modulePathNameWithoutIndexAndDefault |
| 9 | + ,nullif(split(ts.globalFqn, '".')[1], 'default') AS symbolName |
| 10 | + ,split(nullif(reverse(split(reverse(ts.globalFqn), '@')[0]), ts.globalFqn), '/')[0] AS namespaceName |
| 11 | + ,(ts.globalFqn contains '/node_modules/') AS isNodeModule |
| 12 | + ,((NOT ts.globalFqn STARTS WITH '/') AND size(split(ts.globalFqn, '/')) < 3) AS isUnresolvedImport |
| 13 | + ,reverse(split(reverse(class.globalFqn), '.')[0]) AS optionalClassName |
12 | 14 | WITH * |
13 | | - ,reverse(split(reverse(moduleNameWithoutIndex), '/')[0]) AS indexedName |
14 | | - ,coalesce('@' + nullif(namespaceName, ''), '') AS namespaceNameWithAtPrefixed |
| 15 | + ,split(reverse(split(reverse(modulePathNameWithoutIndexAndDefault), '/')[0]), '.')[0] AS indexAndExtensionOmittedName |
| 16 | + ,replace(moduleName, nullif(split(moduleName, '.')[0], moduleName) + '.', '') AS moduleNameExtensionExtended |
| 17 | + ,nullif(reverse(split(reverse(moduleName), '.')[0]), moduleName) AS moduleNameExtension |
| 18 | + ,coalesce('@' + nullif(namespaceName, ''), '') AS namespaceNameWithAtPrefixed |
| 19 | + ,replace(symbolName, coalesce(optionalClassName + '.', ''), '') AS symbolNameWithoutClassName |
15 | 20 | SET ts.namespace = namespaceNameWithAtPrefixed |
16 | | - ,ts.module = moduleName |
17 | | - ,ts.name = coalesce(symbolName, indexedName) |
| 21 | + ,ts.module = modulePathName |
| 22 | + ,ts.moduleName = moduleName |
| 23 | + ,ts.name = coalesce(symbolNameWithoutClassName, indexAndExtensionOmittedName) |
| 24 | + ,ts.extensionExtended = moduleNameExtensionExtended |
| 25 | + ,ts.extension = moduleNameExtension |
18 | 26 | ,ts.isNodeModule = isNodeModule |
19 | 27 | ,ts.isUnresolvedImport = isUnresolvedImport |
20 | 28 | ,ts.isExternalImport = isNodeModule OR isUnresolvedImport |
|
0 commit comments