Skip to content

Add support for getters & setters in objects #26

Description

@Etheryte

Currently, objects with getters and setters are not handled correctly:

const input = {
    _foo: null,
    get foo() {
        return this._foo;
    },
    set foo(value) {
        this._foo = value;
    }
};

const output = "{_foo:null,foo:null}";

This problem can be solved by adding an extra case to the object stringification logic that checks for the given descriptors:

const descriptor = Object.getOwnPropertyDescriptor(obj, key);
if (descriptor && (descriptor.get || descriptor.set)) { ... }

I made a demo in a forked repo with this commit demonstrating the approach.
Sadly, I didn't have time to figure out all of the lexer logic on the go so it isn't clean enough for a flat out PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions