Skip to content

Add (and fix) failing test of function parameter bindings in a catch block#4880

Merged
hzoo merged 2 commits intobabel:masterfrom
benjamn:fix-function-in-catch
Dec 8, 2016
Merged

Add (and fix) failing test of function parameter bindings in a catch block#4880
hzoo merged 2 commits intobabel:masterfrom
benjamn:fix-function-in-catch

Conversation

@benjamn
Copy link
Copy Markdown
Contributor

@benjamn benjamn commented Nov 21, 2016

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes/yes
Fixed tickets #4880
License MIT
Doc PR no
Dependency Changes no

This test can be run in isolation via the following command:

TEST_GREP='block-scoping.*function in catch' make test-only

This test fails because BlockScoping#getLetReferences accidentally considers the parameters of the function declaration as let bindings in the catch scope. When the name of the catch parameter is the same as one of the function's parameter names, the function declaration will be unnecessarily wrapped to isolate its parameters from the outer scope.

While the extra wrapping may not seem harmful in this case, this behavior is a symptom of a deeper problem that causes very subtle bugs in transform code involving catch parameters and function declarations. This test case was just the simplest example I could find to demonstrate the problem.

I have a proposed fix for this problem that I will push as soon as the tests fail for this commit. Pushed!

This test can be run in isolation via the following command:

  TEST_GREP='block-scoping.*function in catch' make test-only

This test fails because BlockScoping#getLetReferences accidentally
considers the parameters of the function declaration as let bindings in
the catch scope. When the name of the catch parameter is the same as one
of the function's parameter names, the function declaration will be
unnecessarily wrapped to isolate its parameters from the outer scope.

While the extra wrapping may not seem harmful in this case, this behavior
is a symptom of a deeper problem that causes very subtle bugs in transform
code involving catch parameters and function declarations. This test case
was just the simplest example I could find to demonstrate the problem.

I have a proposed fix for this problem that I will push as soon as the
tests fail for this commit.
@benjamn
Copy link
Copy Markdown
Contributor Author

benjamn commented Nov 21, 2016

Bigger picture: this is the only remaining bug preventing the Regenerator test suite (specifically this test) from passing using the Babel implementation.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 21, 2016

Current coverage is 89.35% (diff: 100%)

Merging #4880 into master will not change coverage

@@             master      #4880   diff @@
==========================================
  Files           196        196          
  Lines         14022      14022          
  Methods        1460       1460          
  Messages          0          0          
  Branches       3263       3263          
==========================================
  Hits          12529      12529          
  Misses         1493       1493          
  Partials          0          0          

Powered by Codecov. Last update 7e02027...0930101

benjamn added a commit to facebook/regenerator that referenced this pull request Nov 21, 2016
Note that this test still runs and passes in native Node.
@benjamn benjamn changed the title Add failing test of function parameter bindings in a catch block Add (and fix) failing test of function parameter bindings in a catch block Nov 29, 2016
@hzoo hzoo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Dec 2, 2016
@hzoo hzoo merged commit 26b4e09 into babel:master Dec 8, 2016
Jessidhia pushed a commit to Jessidhia/babel that referenced this pull request Dec 8, 2016
* master:
  update `regenerator-runtime` in `babel-polypill` (babel#4966)
  Temp fix for make watch [skip ci] (babel#4967)
  Add (and fix) failing test of function parameter bindings in a catch block (babel#4880)
  Upgrade regenerator-runtime to version 0.10.0. (babel#4877)
  Add `/.test` and `/src` to `babel-plugin-transform-regenerator` `.npmignore`. (babel#4961) [skip ci]
  Only base async fn arity on non-default/non-rest params - fixes babel#4891 (babel#4901)
  Add generator support for Import (babel#4945)
panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
…block (babel#4880)

* Add failing test of function parameter bindings in a catch block.

This test can be run in isolation via the following command:

  TEST_GREP='block-scoping.*function in catch' make test-only

This test fails because BlockScoping#getLetReferences accidentally
considers the parameters of the function declaration as let bindings in
the catch scope. When the name of the catch parameter is the same as one
of the function's parameter names, the function declaration will be
unnecessarily wrapped to isolate its parameters from the outer scope.

While the extra wrapping may not seem harmful in this case, this behavior
is a symptom of a deeper problem that causes very subtle bugs in transform
code involving catch parameters and function declarations. This test case
was just the simplest example I could find to demonstrate the problem.

I have a proposed fix for this problem that I will push as soon as the
tests fail for this commit.

* Make BlockScoping#getLetReferences ignore function parameters.
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 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 PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants