Skip to content

Commit

Permalink
Activate method memoizing + keep attributes of method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kochelmonster committed Jan 7, 2022
1 parent bc1f3b4 commit c4a751d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
25 changes: 15 additions & 10 deletions transcrypt/modules/org/transcrypt/__core__.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,28 @@ export function __init__ (module) {
export function __get__ (aThis, func, quotedFuncName) {// Param aThis is thing before the dot, if it's there
if (aThis) {
if (aThis.hasOwnProperty ('__class__') || typeof aThis == 'string' || aThis instanceof String) { // Object before the dot
var bound = function () { // Return bound function, code duplication for efficiency if no memoizing
var args = [] .slice.apply (arguments); // So multilayer search prototype, apply __get__, call curry func that calls func
return func.apply (null, [aThis.__proxy__ ? aThis.__proxy__ : aThis] .concat (args));
};

if (quotedFuncName) { // Memoize call since fcall is on, by installing bound function in instance
Object.defineProperty (bound, "name", {value:quotedFuncName})
// copy addintional attributes
for(var n in func) {
bound[n] = func[n];
}
bound.__repr__ = function() {
return "method {} of {}".format(quotedFuncName, repr(aThis)); };

Object.defineProperty (aThis, quotedFuncName, { // Will override the non-own property, next time it will be called directly
value: function () { // So next time just call curry function that calls function
var args = [] .slice.apply (arguments);
return func.apply (null, [aThis] .concat (args));
},
value: bound,
writable: true,
enumerable: true,
configurable: true
});
}
var bound = function () { // Return bound function, code duplication for efficiency if no memoizing
var args = [] .slice.apply (arguments); // So multilayer search prototype, apply __get__, call curry func that calls func
return func.apply (null, [aThis.__proxy__ ? aThis.__proxy__ : aThis] .concat (args));
};
bound.__org__ = func
return bound
return bound;
}
else { // Class before the dot
return func; // Return static method
Expand Down
10 changes: 9 additions & 1 deletion transcrypt/modules/org/transcrypt/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ def pushPropertyAccessor(functionName):
isClassMethod = False
isStaticMethod = False
isProperty = False
keep_name = False
getter = '__get__'

if node.decorator_list:
Expand Down Expand Up @@ -2693,6 +2694,7 @@ def pushPropertyAccessor(functionName):
self.emit ('{}: ', self.filterId (nodeName))
else:
self.emit ('get {} () {{return {} (this, ', self.filterId (nodeName), getter)
keep_name = True
elif isGlobal:
if type (node.parentNode) == ast.Module and not nodeName in self.allOwnNames:
self.emit ('export ')
Expand Down Expand Up @@ -2725,7 +2727,8 @@ def pushPropertyAccessor(functionName):
if isStaticMethod:
self.emit ('get {} () {{return {}function', self.filterId (nodeName), 'async ' if anAsync else '')
else:
self.emit ('get {} () {{return {} (this, {}function', self.filterId (nodeName), getter, 'async ' if anAsync else '')
keep_name = True
self.emit ('get {} () {{return {} (this, ({}function', self.filterId (nodeName), getter, 'async ' if anAsync else '')
elif isGlobal:
if type (node.parentNode) == ast.Module and not nodeName in self.allOwnNames:
self.emit ('export ')
Expand Down Expand Up @@ -2768,6 +2771,11 @@ def pushPropertyAccessor(functionName):

if decorate:
self.emit (')' * decoratorsUsed)
if keep_name:
self.emit (', "{}"', self.filterId (nodeName))

elif keep_name:
self.emit ('), "{}"', self.filterId (nodeName))

if isMethod:
if not jsCall:
Expand Down

0 comments on commit c4a751d

Please sign in to comment.