rrdelaney / ReasonablyTyped

:diamond_shape_with_a_dot_inside: Converts Flow and TypeScript definitions to Reason interfaces
https://rrdelaney.github.io/ReasonablyTyped/
MIT License
518 stars 24 forks source link

Import statements #30

Closed rrdelaney closed 7 years ago

rrdelaney commented 7 years ago

We should process import statements to be modules.

Spec

If there is a known binding in reasonml-community, transform the import into aliasing from that. Error on absolute imports without known modules.

For relative imports, use our own module transforming logic and assumer ReasonablyTyped will also process it.

For example, with the statement:

import type { $Request } from 'express'

we should look at the express bindings and emit:

type request = Express.Request.t

based on the following code: https://github.com/reasonml-community/bs-express/blob/master/src/express.re#L21-L22

For a local import such as:

import type { myThing } from './thing'

should be transformed to:

type myThing = Thing.myThing

Implementation details

You'll probably need to match on import statements in statement_to_program, and create a new BsDecl variant, then finally the output in declaration_to_code.