Skip to content

Remove the Object.create call from the source? #23

Open
@AndrewRayCode

Description

@AndrewRayCode

I recognize the Object.create call from Dougy Crock's top down operator precedence article. I don't think it's needed here though? The problem with this is when I try to clone an AST node with:

const clone = {...node};

It doesn't work, because none of the keys on node are enumerable since they're made with Object.create(). So those keys don't show up on the cloned node. It took me a while to debug why an operation wasn't working, and it was because my AST node clone was missing the .data property.

For anyone else who has this unlikely issue, for now I'm converting this node to all enumerable keys (I think) with this function:

const junk2js = node => ({
  ...node,
  ...Object.getPrototypeOf(node)
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions