jorendorff / js-loaders

Pseudoimplementation of the proposed ES6 module loaders.
54 stars 7 forks source link

Remove Loader.define(); disallow anonymous modules. #91

Closed johnjbarton closed 10 years ago

johnjbarton commented 10 years ago

As far as I can tell, Loader.define() and Loader.module() accomplish the same task. We only need one of these functions.

In my opinion we should not support anonymous modules. Our long experience with anonymous eval() shows that it is a source of many pointless problems in JS development.

Note that anonymous <module> or <script> tags are (somewhat) better than anonymous module() or eval() because the line number of the tag gives a unique name for the source. (Tags added by document.write() or element.appendChild() are similar to anonymous module/eval; hopefully module loaders will eliminate the need for those shenanigans).

jorendorff commented 10 years ago

As far as I can tell, Loader.define() and Loader.module() accomplish the same task.

Loader.define() only installs modules into the registry. The module bodies are not evaluated until needed.

Loader.module() additionally runs the module body. It's like an asynchronous eval that can use import and export syntax.

Closing. I don't see us disallowing anonymous modules. They're useful. We can fix the loss of context either in tooling or by making some changes in issue #82. If you're sure anonymous modules are bad, I recommend taking it to es-discuss.