simplfy function name inference wrapper - closes #1002

This commit is contained in:
Sebastian McKenzie 2015-04-02 02:37:00 +11:00
parent f88a4147a6
commit cfff7aa6fb
7 changed files with 49 additions and 50 deletions

View File

@ -25,13 +25,12 @@ var wrap = function (state, method, id, scope) {
var template = util.template(templateName, {
FUNCTION: method,
FUNCTION_ID: id,
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
WRAPPER_KEY: scope.generateUidIdentifier(id.name + "Wrapper")
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
});
// shim in dummy params to retain function arity, if you try to read the
// source then you'll get the original since it's proxied so it's all good
var params = template.callee.body.body[0].declarations[0].init.params;
var params = template.callee.body.body[0].params;
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
params.push(scope.generateUidIdentifier("x"));
}

View File

@ -1,11 +1,11 @@
(function (FUNCTION_KEY) {
var WRAPPER_KEY = function* FUNCTION_ID() {
return yield* FUNCTION_KEY.apply(this, arguments);
function* FUNCTION_ID() {
return yield* FUNCTION_ID.apply(this, arguments);
}
FUNCTION_ID.toString = function () {
return FUNCTION_ID.toString();
};
WRAPPER_KEY.toString = function () {
return FUNCTION_KEY.toString();
};
return WRAPPER_KEY;
return FUNCTION_ID;
})(FUNCTION)

View File

@ -1,11 +1,11 @@
(function (FUNCTION_KEY) {
var WRAPPER_KEY = function FUNCTION_ID() {
function FUNCTION_ID() {
return FUNCTION_KEY.apply(this, arguments);
};
}
WRAPPER_KEY.toString = function () {
return FUNCTION_KEY.toString();
};
FUNCTION_ID.toString = function () {
return FUNCTION_ID.toString();
}
return WRAPPER_KEY;
return FUNCTION_ID;
})(FUNCTION)

View File

@ -1,15 +1,15 @@
"use strict";
var i = (function (_i) {
var _iWrapper = function i() {
function i() {
return _i.apply(this, arguments);
}
i.toString = function () {
return i.toString();
};
_iWrapper.toString = function () {
return _i.toString();
};
return _iWrapper;
return i;
})(function () {
i = 5;
});
@ -17,4 +17,4 @@ var i = (function (_i) {
var j = function j() {
var _ = 5;
j = _.j;
};
};

View File

@ -8,15 +8,15 @@ var obj = {
},
h: (function (_h) {
var _hWrapper = function h() {
function h() {
return _h.apply(this, arguments);
}
h.toString = function () {
return h.toString();
};
_hWrapper.toString = function () {
return _h.toString();
};
return _hWrapper;
return h;
})(function () {
console.log(h);
}),
@ -24,4 +24,4 @@ var obj = {
m: function m() {
doSmth();
}
};
};

View File

@ -5,27 +5,27 @@ var f = function f() {
};
var f = (function (_f) {
var _fWrapper = function f(_x) {
function f(_x) {
return _f.apply(this, arguments);
}
f.toString = function () {
return f.toString();
};
_fWrapper.toString = function () {
return _f.toString();
};
return _fWrapper;
return f;
})(function (f) {});
var obj = {
f: (function (_f) {
var _fWrapper = function f(_x) {
function f(_x) {
return _f.apply(this, arguments);
}
f.toString = function () {
return f.toString();
};
_fWrapper.toString = function () {
return _f.toString();
};
return _fWrapper;
return f;
})(function (f) {})
};
};

View File

@ -1,15 +1,15 @@
"use strict";
var f = (function (_f) {
var _fWrapper = function f() {
function f() {
return _f.apply(this, arguments);
}
f.toString = function () {
return f.toString();
};
_fWrapper.toString = function () {
return _f.toString();
};
return _fWrapper;
return f;
})(function () {
console.log(f, g);
});
});