Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Merging exports and imports

Dániel Stein edited this page Feb 28, 2016 · 3 revisions

Import

import { doStuff } from "export";

doStuff();

Export

export default function doStuff() {}

Graph

Import AST and scopes

.png .pdf .dot

Notes

Transformation

  1. Find the imported IdentifierExporession in the GlobalScope node's items list.
  2. Find the connected upstream Variable node.
  3. Find the Declaration for the Export that has a Node with the same BindingIdentifier as the import.
  4. Connect the Variable on the import side to the Declaration on the export side with a declarations 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