Skip to content

Assignment pattern support in transform-object-rest-spread - #10738

Open
JLHwung wants to merge 9 commits into
babel:mainfrom
JLHwung:fix-10735
Open

JLHwung wants to merge 9 commits into
babel:mainfrom
JLHwung:fix-10735

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 19, 2019 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Fixes #10735
Patch: Bug Fix? Yes
Tests Added + Pass? Yes
License MIT

In this PR we add support for assignment pattern in transform-object-rest-spread.

When the object pattern is inside an assignment pattern, the memoized reference for both objRef and the right(default value) of AssignmentPattern will be created so that they will only be executed once.

function createObjRefExpression(path, objRef) {
let impureDefaultValueDeclarator;
let objRefExpression;
if (path.parentPath?.isAssignmentPattern()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When can parentPath be null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

parentPath can be undefined when traverse.hasType is called, but I admit I may be too paranoid here.

classes
} = this
} = props,
InputPropsOther = babelHelpers.objectWithoutProperties((_props$Global = props.Global, _props$Global !== void 0 ? _props$Global : this), ["classes"]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is accessing props.Global twice: once for the destructuring, and once here.

@JLHwung JLHwung Nov 20, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! It seems that this issue has been around for a while. I would suggest we address it in a separate PR.

#10743 is created.

nicolo-ribaudo
nicolo-ribaudo previously approved these changes Nov 20, 2019
@nicolo-ribaudo

nicolo-ribaudo commented Apr 2, 2020 •

Copy link
Copy Markdown
Member

@JLHwung It has been almost six months since you wrote this code: I think your review/:heavy_check_mark: would be "valid" because you have a ,uch deeper understanding of how things work now.

@nicolo-ribaudo nicolo-ribaudo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

var {
  InputProps: { ...x } = alert(1),
} = { InputProps: {} };

This code shouldn't alert 1, but when transpiled it does.

@@ -0,0 +1,12 @@
var _foo, _props$InputProps;

const _foo = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_foo is declared twice.

@nicolo-ribaudo
nicolo-ribaudo dismissed their stale review April 6, 2020 19:45

@JLHwung I'm postponing this PR to a different version that 7.9.5 because of the two bugs I reported above 😅

@nicolo-ribaudo nicolo-ribaudo removed this from the v7.9.5 milestone Apr 6, 2020
@JLHwung
JLHwung changed the base branch from master to main July 30, 2020 16:56
@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit aec3f77:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/26662/

This branch has not been deployed

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

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Object Rest/Spread

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rest spread ignores default values

4 participants