Brian Di Palma (2014-10-05T15:51:39.000Z)
domenic at domenicdenicola.com (2014-10-15T18:56:24.087Z)
I'm probably not understanding all the issues here but I'm also not explaining my suggestion well either. The way I see the two issues you raised is like this. 1. I think you mean that a parser wants to fail quickly if it comes across an identifier that was not previously declared as an import but that could be declared as one deeper in the module file? The simple solution to that problem is to not allow binding references before their import statements. 99.9% of modules will declare their imports at the top of the file anyway, most developers won't come across this restriction very often. It doesn't take away functionality, it's a useless degree of freedom and I can't think of any language where it's good practice to import/require etc anywhere but at the head of a module/class. I imagine these fast parsers work top down as the packets are streamed in from the network so this rule should work well for them? 2. I didn't explain this part well. I meant for the "@global" import to be a special one who's bindings will not go through the same checks that other modules do. In a browser importing global would return window. This should make it trivial to upgrade current code to ES6 modules while still allowing much stricter checks in modules. You would use tools that take the ES5 code and scan it for free identifiers and import them from "@global". This then allows you to gradually move them all into ES6 modules. ```js import * as global, {Date, XMLHttpRequest} from "@global"; ``` All bindings provided by "@global" bypass the normal bindings checks. Think of it as a reverse "use strict", currently to the do the right thing developers have to add an extra line at the top of all their scripts. With ES6 modules they should instead be required to add an extra line to do the wrong but temporarily necessary wrong thing. Adding this extra line is highly amenable to automation/tooling which developers will be using anyway when moving to ES6 modules. With time this line will be removed as their code is moved into modules or new versions of global classes are provided in standard modules. This would allow developers to still use "Date" as their constructor and not have it accidentally use the older version if a new one is added to standard modules. So by default an ES6 module starts of with a totally clean slate, it has no external state in its scope. Only if the developer chooses will the module be exposed to the madness of the global scope. Would this help macros or typing to be added to those modules with no access to the global? That would be a nice carrot to get developers to try and delete that line at the top of their module.