Skip to content

Redeclaring a variable counts as a modification - #6219

Merged
jridgewell merged 2 commits into
babel:masterfrom
RubenVerborgh:fix/redeclaration-const
Sep 9, 2017
Merged

jridgewell merged 2 commits into
babel:masterfrom
RubenVerborgh:fix/redeclaration-const

Conversation

@RubenVerborgh

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues Fixes #6217.
Patch: Bug Fix? Yes.
Major: Breaking Change? No.
Minor: New Feature? No.
Tests Added/Pass? Yes.
Spec Compliancy? Yes.
License MIT
Doc PR No.
Any Dependency Changes? No.

When a variable is redeclared (as in var a = 1; var a = 2;), this PR ensures that the second declaration is no longer regarded as a constant.

@mention-bot

Copy link
Copy Markdown

@RubenVerborgh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kassens, @hzoo and @existentialism to be potential reviewers.

@jridgewell jridgewell 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.

This should have been fixed in #5745. I'd gladly accept the tests, though!

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

@jridgewell Woops, didn't find #5745 with issue search. Different keywords I guess.

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Actually, @jridgewell, could you have another look? The unit tests I added fail without my fix, and #5745 already made it to master.

@jridgewell

Copy link
Copy Markdown
Member

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Indeed, you just concat but don't update.

I personally think the error is where I fixed it (incorrect assumption of a mapping key not existing yet), but I can migrate to the other fix.

@jridgewell

Copy link
Copy Markdown
Member

We can revert #5745 with this. Either's fine.

kind: kind,
});
// A redeclaration of an existing variable is a modification
if (name in this.bindings) {

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.

Use #hasOwnBinding, please.

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.

Actually, just check if (existing)

@RubenVerborgh RubenVerborgh Sep 9, 2017 •

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.

if(this.hasOwnBinding(name)) works; can't do the second suggestion because no existing is in scope. How do I proceed?

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.

Sorry, it's local.

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.

Check, works. Pushed new version.

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Same with me. Maybe consider reopening #6217 until this is fixed?

@RubenVerborgh

RubenVerborgh commented Sep 9, 2017 •

Copy link
Copy Markdown
Contributor Author

@jridgewell What should we do about this failure: https://travis-ci.org/babel/babel/jobs/273498334#L1073? Is the new version correct or not?

@jridgewell

Copy link
Copy Markdown
Member

Just update the test, the new output is fine.

@RubenVerborgh

RubenVerborgh commented Sep 9, 2017 •

Copy link
Copy Markdown
Contributor Author

Made all the changes, tests pass. Now additionally removing unneeded code from #5745, keeping its tests.

@babel-bot

babel-bot commented Sep 9, 2017 •

Copy link
Copy Markdown
Collaborator

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

@jridgewell
jridgewell merged commit 6560a29 into babel:master Sep 9, 2017
@RubenVerborgh
RubenVerborgh deleted the fix/redeclaration-const branch September 9, 2017 03:04
@lock lock Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variable redeclarations are not recognized as modifications

4 participants