Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python member 'name' needs to be translated for javascript #47

Closed
shaolo1 opened this issue May 14, 2016 · 2 comments
Closed

Python member 'name' needs to be translated for javascript #47

shaolo1 opened this issue May 14, 2016 · 2 comments
Assignees
Labels

Comments

@shaolo1
Copy link

shaolo1 commented May 14, 2016

Python

def foo():
    class Bar:
        def __init__(self, name):
            self.name = name

    b = Bar('foo')
    print("b.name =", b.name)

foo()

Generated Javascript

var foo = function () {
            var Bar = __class__ ('Bar', [object], {
                get __init__ () {return __get__ (this, function (self, name) {
                    self.name = name;
                });}
            });
            var b = Bar ('foo');
            print ('b.name =', b.name);
        };

Causes
TypeError: "name" is read-only

I've not looked at the fix, but this seems similar to https://github.com/JdeH/Transcrypt/issues/24

@JdeH JdeH self-assigned this May 15, 2016
@JdeH JdeH added the IS: bug label May 15, 2016
@JdeH
Copy link
Collaborator

JdeH commented May 16, 2016

I've added a default alias for identifier 'name' in the newest version that I am about to upload, this will now translate to:

    var foo = function () {
        var Bar = __class__ ('Bar', [object], {
            get __init__ () {return __get__ (this, function (self, py_name) {
                self.py_name = py_name;
            });}
        });
        var b = Bar ('foo');
        print ('b.name =', b.py_name);
    };

@JdeH
Copy link
Collaborator

JdeH commented May 17, 2016

Fixed

@JdeH JdeH closed this as completed May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants