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

fix: make letConst transpilation add explicit keys when appropriate #229

Merged
merged 2 commits into from Nov 15, 2019

Conversation

luiscubal
Copy link
Contributor

When letConst transpilation is on, buble renames some variables, such as x->x$1. However, when shorthand properties are used, this causes the property key to change.
The appropriate fix is to make those properties no longer be shorthand, so something like { x : x$1 } is used.
This applies both to object literals and object destructuring patterns.

The destructuring and concise property transpilation options hide this bug, so this commit only improves the situation for use-cases where letConst transpilation is used without those options.

When letConst transpilation is on, buble renames some variables,
such as x->x$1. However, when shorthand properties are used, this
causes the property key to change.
The appropriate fix is to make those properties no longer be
shorthand, so something like { x : x$1 } is used.
This applies both to object literals and object destructuring
patterns.

The destructuring and concise property transpilation options hide
this bug, so this commit only improves the situation for use-cases
where letConst transpilation is used without those options.
Copy link
Collaborator

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for taking on this!

declaration.name = alias;
code.overwrite(
declaration.node.start,
declaration.node.end,
alias,
{ storeName: true }
);
if (declarationParent.type === 'Property' && declarationParent.shorthand) {
declarationParent.shorthand = false;
code.prependLeft(declaration.node.start, `${name}: `);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in the new commit.

@mourner mourner merged commit c26c7d3 into bublejs:master Nov 15, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants