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

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

Open
AndrewRayCode opened this issue Dec 26, 2018 · 0 comments
Open

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

AndrewRayCode opened this issue Dec 26, 2018 · 0 comments

Comments

@AndrewRayCode
Copy link

AndrewRayCode commented Dec 26, 2018

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)
});
@AndrewRayCode AndrewRayCode changed the title Remove the Object.create call from the source Remove the Object.create call from the source? Dec 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant