google / google/closure-compiler

Unexpected strict mode reserved word "let"

Open
#2,560 4 comments 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

tl,dr: I'm getting `function let()` in my advanced compilation output, which is breaking runtime on older browsers.

One of my project's target platform is an old browser not permitting the "let" keyword e.g. as a function name, and our build intermittently fails at runtime in this browser with "Unexpected strict mode reserved word".

The latest case was in this line of output:

```
...function let(e,R,Z,V){...
```

Here's how we're configuring the build (we use the Java API directly). I'm already trying to explicitly avoid `let`, having been unable to find a place in the Closure Compiler source where you already do this:
```
RandomNameGenerator rng = new RandomNameGenerator(new Random(buildRevision.hashCode()));

rng.reset(new HashSet<>(Arrays.asList("break", "case", "catch", "class", "const",
"continue", "debugger", "default", "delete", "do", "else", "export", "extends",
"finally", "for", "function", "if", "import", "in", "instanceof", "new", "return",
"super", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with",
"yield", "enum", "implements", "interface", "let", "package", "private",
"protected", "public", "static", "await", "abstract", "boolean", "byte", "char",
"double", "final", "float", "goto", "int", "long", "native", "short",
"synchronized", "throws", "transient", "volatile")), "", null);

options.setNameGenerator(rng);
```
I'm assuming that
```
NameGenerator.reset()
```
is being called somewhere, and my preferences are being overwritten/cleared.

Is there another way to prevent reserved words being used as names?

From https://groups.google.com/forum/#!topic/closure-compiler-discuss/QmKBuR2kJ6s

Contributor guide

Open the contributing guide

Research direction

Start by tracing the RandomNameGenerator configuration through NameGenerator.reset() in the Java API, then reproduce the advanced compilation case that emits function let(e,R,Z,V). Verify the resulting output no longer uses reserved words such as let as generated names, and add or run a regression test for the emitted function names.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.