google / google/closure-compiler

Logical assignment breaks on class static properties

Open
#4,288 10 comments 0 reactions 1 assignee Claimed by @shicks View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

I suspect this is because the variable flattener doesn't like how previous phases transpile local assignment in a way that creates a temporary variable.

Input:
```js
class MyClass {}
console.log(() => {
return (MyClass.myField ??= {});
});
```

with flags:
```
-O ADVANCED
--js in.js
--language_in ECMASCRIPT_NEXT
--language_out ECMASCRIPT_2020
```

Output:
```js
class a{}console.log(()=>a.g??{});
```

Expected output:
```js
// any of
class a{}console.log(()=>a.g??={});
var x;console.log(() => x??={});
var x;console.log(() => x??(x={}));
class a{};console.log(() => a.g??(a.g={}));
```

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.