Closed
Description
Currently we are removing all define()
wrappers from modules, this makes "nicer" looking compiled code but can lead to bugs, imagine a case like this:
// A.js
define(function () {
var locals = {test: 'TEST'};
function A() {
console.log(locals.test);
}
return A;
});
// B.js
define(function () {
var locals = {};
function B() {
//do something
}
});
// Entry.js
define(['A','B'], function (A, B) {
A(); // should log TEST
})
Currenty we are compiling it to something like that:
// build.js
var locals = {test: 'TEST'};
function A() {
console.log(locals.test);
}
var locals = {};
function B() {
//do something
}
A(); // should log TEST
This is nice while don't have modules that use the same name. But today I stumbled accross one of these cases like the locals
variable from the example.
While this safes some memory and memory management (due to less scopes) for the browser, it make it harder for us and is error prone.
I would change the built process to produce something like that:
var A = (function () {
var locals = {test: 'TEST'};
function A() {
console.log(locals.test);
}
return A;
})();
var B = (function () {
var locals = {};
/* ...*/
})();
/* ... */
What do you think ?