Skip to content

Commit

Permalink
little minimize umd wrapper and $.def
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 21, 2015
1 parent 6fb463d commit a554185
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
6 changes: 2 additions & 4 deletions build/build.ls
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,14 @@ module.exports = ({modules = [], blacklist = [], library = no}, next)!->

next null """
#banner
!function(undefined){
!function(__e, __g, undefined){
'use strict';
var __e = null, __g = null;
#script
// CommonJS export
if(typeof module != 'undefined' && module.exports)module.exports = __e;
// RequireJS export
else if(typeof define == 'function' && define.amd)define(function(){return __e});
// Export to global object
else __g.core = __e;
}();
}(1, 1);
"""
2 changes: 1 addition & 1 deletion build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion library/modules/$.core.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var core = {};
module.exports = core;
if(typeof __e != 'undefined')__e = core; // eslint-disable-line no-undef
if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
9 changes: 5 additions & 4 deletions library/modules/$.def.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var global = require('./$.global')
, isFunction = require('./$.is-function')
, core = require('./$.core');
, core = require('./$.core')
, PROTOTYPE = 'prototype';
function ctx(fn, that){
return function(){
return fn.apply(that, arguments);
Expand All @@ -18,7 +19,7 @@ function $def(type, name, source){
, isGlobal = type & $def.G
, isProto = type & $def.P
, target = isGlobal ? global : type & $def.S
? global[name] : (global[name] || {}).prototype
? global[name] : (global[name] || {})[PROTOTYPE]
, exports = isGlobal ? core : core[name] || (core[name] = {});
if(isGlobal)source = name;
for(key in source){
Expand All @@ -36,12 +37,12 @@ function $def(type, name, source){
exp = function(param){
return this instanceof C ? new C(param) : C(param);
};
exp.prototype = C.prototype;
exp[PROTOTYPE] = C[PROTOTYPE];
}(out);
else exp = isProto && isFunction(out) ? ctx(Function.call, out) : out;
// export
exports[key] = exp;
if(isProto)(exports.prototype || (exports.prototype = {}))[key] = out;
if(isProto)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;
}
}
module.exports = $def;
4 changes: 2 additions & 2 deletions library/modules/$.global.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var global = typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
if(typeof __g != 'undefined')__g = global; // eslint-disable-line no-undef
module.exports = global;
module.exports = global;
if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
2 changes: 1 addition & 1 deletion modules/$.core.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var core = {};
module.exports = core;
if(typeof __e != 'undefined')__e = core; // eslint-disable-line no-undef
if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
7 changes: 4 additions & 3 deletions modules/$.def.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var global = require('./$.global')
, core = require('./$.core')
, hide = require('./$.hide')
, $redef = require('./$.redef')
, isFunction = require('./$.is-function');
, isFunction = require('./$.is-function')
, PROTOTYPE = 'prototype';
function ctx(fn, that){
return function(){
return fn.apply(that, arguments);
Expand All @@ -21,7 +22,7 @@ function $def(type, name, source){
, isGlobal = type & $def.G
, isProto = type & $def.P
, target = isGlobal ? global : type & $def.S
? global[name] || (global[name] = {}) : (global[name] || {}).prototype
? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE]
, exports = isGlobal ? core : core[name] || (core[name] = {});
if(isGlobal)source = name;
for(key in source){
Expand All @@ -36,7 +37,7 @@ function $def(type, name, source){
if(target && !own)$redef(target, key, out);
// export
if(exports[key] != out)hide(exports, key, exp);
if(isProto)(exports.prototype || (exports.prototype = {}))[key] = out;
if(isProto)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;
}
}
module.exports = $def;
4 changes: 2 additions & 2 deletions modules/$.global.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var global = typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();
if(typeof __g != 'undefined')__g = global; // eslint-disable-line no-undef
module.exports = global;
module.exports = global;
if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
9 changes: 5 additions & 4 deletions modules/library/$.def.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var global = require('./$.global')
, isFunction = require('./$.is-function')
, core = require('./$.core');
, core = require('./$.core')
, PROTOTYPE = 'prototype';
function ctx(fn, that){
return function(){
return fn.apply(that, arguments);
Expand All @@ -18,7 +19,7 @@ function $def(type, name, source){
, isGlobal = type & $def.G
, isProto = type & $def.P
, target = isGlobal ? global : type & $def.S
? global[name] : (global[name] || {}).prototype
? global[name] : (global[name] || {})[PROTOTYPE]
, exports = isGlobal ? core : core[name] || (core[name] = {});
if(isGlobal)source = name;
for(key in source){
Expand All @@ -36,12 +37,12 @@ function $def(type, name, source){
exp = function(param){
return this instanceof C ? new C(param) : C(param);
};
exp.prototype = C.prototype;
exp[PROTOTYPE] = C[PROTOTYPE];
}(out);
else exp = isProto && isFunction(out) ? ctx(Function.call, out) : out;
// export
exports[key] = exp;
if(isProto)(exports.prototype || (exports.prototype = {}))[key] = out;
if(isProto)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;
}
}
module.exports = $def;

0 comments on commit a554185

Please sign in to comment.