google / google/closure-compiler
Overly aggressive inlining of Date expressions
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Consider this JavaScript code:
```javascript
console.log(
(function() {
var start = new Date().getTime();
var end = new Date().getTime();
return end - start;
})()
);
```
Passing this through advanced optimizations yields
```javascript
console.log((new Date).getTime()-(new Date).getTime());
```
which has different semantics: The unoptimized version will calculate an end date after the start date, and the difference will be non-negative. The optimized version will evaluate left to right, calculating the left date first, followed by the right date, producing non-positive values.
Example, using Nashorn:
```
jjs> (new Date).getTime()-(new Date).getTime()
-3
```
Contributor guide
Assessment
This issue has not been assessed yet.