This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Proof of concept dead code search example
Soma Lucz edited this page Apr 13, 2017
·
1 revision
/**
* Initial setup after subgraph insert
*/
MATCH // Match called FunctionDeclarations for every CallExpression
(call:CallExpression)-[:callee]->(:IdentifierExpression)
<--(:Either)<-[:node]-(:Reference)-[:references]-(:Variable)
-[:declarations]->(:Declaration)-[:node]->(bindingIdentifier)
<-[:name]-(fd:FunctionDeclaration)
MATCH // List every call from a function body
(fun:FunctionDeclaration)-[*]->(call:CallExpression)
MERGE // Create a calls relationship between the caller
// FunctionDeclaration and the called FunctionDeclaration
(fun)-[:calls]->(fd)
/**
* Get every FunctionDeclaration used by the export
*/
MATCH // List the exported FunctionDeclaration and every
// FunctionDeclaration that this may use
(main)-[:items]->(:ExportDeclaration)-[:declaration]
->(fd:FunctionDeclaration)-[:calls*]->(f)
RETURN
fd, f
/**
* Get not used FunctionDeclarations
*/
MATCH
// Find the exported FunctionDeclaration that may be an entrance point
(main)-[:items]->(:ExportDeclaration)-[:declaration]->(fd:FunctionDeclaration)
MATCH // Find every FunctionDeclaration that should be available through the
// entrance points
(find:FunctionDeclaration)
WHERE // List the ones that are not available (Kleene closure) from the
// entrance nodes (thus are not the entrance nodes "<>").
(
NOT
(fd)-[:calls*]->(find)
) AND (
find <> fd
) AND (
main:Script OR main:Module
)
RETURN
find
Codemodel-Rifle // Graph-based incremental static analysis of ECMAScript 6 source code repositories
All code in this repository is available under the Eclipse Public License v1.0 and is supported by the MTA-BME Lendület Research Group on Cyber-Physical Systems.