sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 211 forks source link

Handle forwarding bindings better #737

Closed disnet closed 7 years ago

disnet commented 7 years ago

fixes #736

Turns out there was an even simpler repro:

// mod.js
export var x = 1;

// main.js
import { x } from './mod.js';

The issue is the design of module hygiene assumes bundling of all the modules #662 and so sets up a forwarding binding for each imported name. This greatly simplifies module bundling (just emit each module and bindings take care of themselves) but since we don't have bundling yet we run into this problem.

The solution is a little hacky, only add forwarding bindings to import names when:

Don't merge just yet, I still need to add tests.

gabejohnson commented 7 years ago

I see now that I couldn't repro because I wasn't compiling both files. I'll reserve further comment until the tests are added.

disnet commented 7 years ago

Ok, tests are added