juliankrispel / jsio-codemods

A bunch of codemods to turn code reliant on the jsio compiler into es6 modules
MIT License
0 stars 0 forks source link

[WIP] - Update 'from' imports #10

Open juliankrispel opened 8 years ago

juliankrispel commented 8 years ago

Because we want to bundle all exported variables in the default export we need to consider the same for imports.

Right now, this bit of jsio syntax:

from device import hideAddressBar as hab;

compiles to this:

import { hab } from 'device';

which quite obviously won't work because hab is bound to the default export.

There's no compatible transform for this really, so instead we need to import the module and then destructure the from:

import device from 'device';
var { hab } = device;

not super pretty but the only way I can see rn. cc @yofreke

yofreke commented 8 years ago

Destructuring might not be the worst option. You would want the transform to look more like:

import device from 'device';
const { hideAddressBar: hab } = device;

I think destructuring is fine for the automatic mods. It doesn't look great, but we will end up doing 90% by hand if we don't start accepting some of these edge cases.

Depending on how many of these cases there are, it might make the most sense to add another mod for restructuring exports / imports. We could then run that on a case by case basis. I am going to get @fairfieldt input on this as well.

fairfieldt commented 8 years ago

We want to convert all of the timestep code to the idiomatic style: import { hab } from 'device';

This seems pretty manageable as a manual process if there's no way to do it automatically.

For the script to convert a game's code, the restructuring looks fine to me

yofreke commented 8 years ago

It sounds like we want to add an environment variable STRICT_MODS (or something), which will change how we handle certain cases, warn or error. This should be one of the cases that toggle (warn during normal use, fail during strict use).

juliankrispel commented 8 years ago

@yofreke that sounds like a nice to have, v2 of these mods I'm thinking. Whaddayathink?

yofreke commented 8 years ago

Adding that as a v2 sounds fine. First deliverable should be the strict variant (for use with library code). Just keep this in mind when writing things, as to not make it too complicated to add later.