google / google/closure-compiler

MakeDeclaredNamesUnique is incorrect when function expression names are shadowed by parameters

Open
#2,746 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

This is a super-specific issue, but it has the potential to cause problems when we move name uniquification earlier, since types will potentially get bound to the wrong names.

The following code demonstrates the issue:
```js
var f; (function f(f) {})
```

In this case, there are effectively four nested scopes: the enclosing scope that declares the `var f`, the function name scope, which declares `function f` that shadows the `var f`, the parameter list scope that declares the parameter `(f)` that immediately shadows the function name, and the function body scope, which is empty here. I don't fully understand why the parameter list needs its own scope. The compiler elides the 2nd scope that holds only the function name. As a result, there's no scope for the compiler to hang this name on, so it doesn't end up being a var anywhere.

I'm currently leaning toward adding some special handling in `ContextualRenamer` and `ContextualRenameInverter` to detect this specific case and give it an arbitrary (invertible) name.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.