babel / babel/minify

Lexical variables in the outermost lexical scope don’t get mangled

Open
#903 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

Lexical variables in the outermost lexical scope don’t get mangled, i.e. they appear to be incorrectly treated as global variables.

**To Reproduce**

Minimal code to reproduce the bug:

```js
// foo.mjs
const foo = 42;
const bar = 64;
```

```sh
$ minify foo.mjs
```

**Actual Output**

```js
const foo=42,bar=64;
```

**Expected Output**

```js
const a=42,b=64;
```

I’m using the `babel-minify` CLI, v0.4.3, with no additional configuration.

As a workaround, I have to wrap my source code in a block: `{ … }`. That way, babel-plugin-minify-mangle-names seems to kick in correctly.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the babel-minify CLI and the foo.mjs example, then inspect babel-plugin-minify-mangle-names and how it handles the outermost lexical scope. Done means the top-level variables are mangled to output such as const a=42,b=64, without requiring an extra block.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.