Feed back and proposal for modules: allow importing ES5 files
程劭非
csf178 at gmail.com
Sat Sep 22 10:29:07 PDT 2012
Hi, everyone,
I noticed that current importing grammar will not work for ES5 files,
I mean there is no way to import one or more es5/es3 files as a module
and import variables from it.
The problem is:
1. There are no "export" keywords in a es5/es3 file, no variables are exported.
2. They might be using more than one files but current mudule grammar
allows only one file as one module.
When the new standard(es6) comes out, I guess a big number of
libraries need updating. And before they finish their work, I think we
need a cheap solution for the new code(es6) to use old
libraries(es5/es3) without modifying their code
For the two points, I was considering two solution:
1. Export all global variable by default.
Anonymous function could be used to protect the global namespace and
most libraries are already using it. So I don't think "export" is
needed.
Exporting all global variable will not pollute the module's user's
namespace for we still need "import" phase.
2. Allow importing multiple files as one module.
This will completely decouple file and module. We need to modify the
ModuleSpecifier grammar:
ModuleSpecifier ::= StringLiteral | Path
===>
ModuleSpecifier ::= ( StringLiteral | Path ) ( "," StringLiteral | Path )*
With this, for example, if I'm using a RSA library like
<http://www-cs-students.stanford.edu/~tjw/jsbn/>, I can do the
following:
import "jsbn.js","prng4.js","rng.js","rsa.js" as RSA;
If I want to use a module depend on jQuery1.3.2, I can do:
import "jQuery1.3.2.js","MyModule.js" as MyModule;
I've mentioned this idea in a reply, post it as a separate thread to
get more feed back :-)
/Shaofei Cheng
More information about the es-discuss
mailing list