Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scope of function declaration binding in constant folding (#643)
Summary: **Summary** This is a possibly incomplete fix for #291, it corrects at least one issue with name shadowing but there might be other problems present in the very large code payload presented in the original issue. The exact bug fixed here happens when a function declares an unused variable shadowing its own name: ```js export function foo() { let foo; } ``` The current code checks whether that the binding corresponding to the function is referenced in the scope of the FunctionDeclaration node, however in Babel that scope is situated inside the body of the function and not in the outer program. Since the binding is retrieved by name, Babel returns informations related to the inner, unreferenced variable and thus the entire function is removed. This fix changes the biding retrieval to read from the parent scope of the FunctionDefinition, which returns the correct binding. **Test plan** An additional test case has been added to verify the function remains in the final output. Pull Request resolved: #643 Reviewed By: MichaReiser Differential Revision: D27324443 Pulled By: motiz88 fbshipit-source-id: 30a9b7244846ad0ff4ba080c96e81dc6f582e5e5
- Loading branch information