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
Merging exports and imports
Dániel Stein edited this page Feb 28, 2016
·
3 revisions
import { doStuff } from "export";
doStuff();
export default function doStuff() {}
- It's easy to see that there are 2 separate AST+Scope graphs with only one connection.
- Both of these graphs would contain one
BindingIdentifier
node with a name ofdoStuff
. - If these are not merged export-time (and they should not be), I only need to merge these nodes based on various rules. See:
- For some reason these two nodes are already merged together. I've used the same
GraphIterator
instance, so if these two were the sameObject
s in Java, they are represented by the same node in the graph. With the static parsing function in Shift this should not happen.
After using separating the same object references and storing them as different graph nodes, the following graph was presented:
- Find the imported
IdentifierExporession
in theGlobalScope
node'sitems
list. - Find the connected upstream
Variable
node. - Find the
Declaration
for theExport
that has aNode
with the sameBindingIdentifier
as the import. - Connect the
Variable
on the import side to theDeclaration
on the export side with adeclarations
relationship.
MATCH
(:ImportDeclaration)-[*]->(importIdentifier:BindingIdentifier)
MATCH
(:GlobalScope)-[:through]->(:HashTable)-[]->(reference:Reference)
-[:node]->(:Either)-[:data]->(identifier:IdentifierExpression)
MATCH
(:ExportDeclaration)-[:declaration]->(:Node)-[:name]
->(exportIdentifier:BindingIdentifier)
MATCH
(exportIdentifier)<-[:node]-(declaration:Declaration)
MATCH
(reference)<-[:references]-(variable:Variable)
WHERE
importIdentifier.name = identifier.name AND
exportIdentifier.name = importIdentifier.name
CREATE UNIQUE
(variable)-[:declarations]->(declaration)
RETURN
importIdentifier, exportIdentifier, variable, declaration
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.