google / google/closure-compiler
Async wrapper functions don't get inlined on advanced compilation
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
When building the following code: ([appspot repro](https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%2540language_in%2520ES_NEXT%250A%252F%252F%2520%2540language_out%2520ES_NEXT%250A%252F%252F%2520%2540debug%2520true%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252Fasync%2520functions%250Aasync%2520function%2520waitLog(message)%257B%250A%2509console.log(message)%253B%250A%257D%250Aasync%2520function%2520wrapperFnWait(message)%257B%250A%2509await%2520waitLog(message)%253B%250A%257D%250A%250A%250A%252F%252Fsynchronous%2520functions%250Afunction%2520directLog(message)%257B%250A%2509console.log(message)%253B%250A%257D%250Afunction%2520wrapperFnDirect(message)%257B%250A%2509directLog(message)%253B%250A%257D%250A%250A%250A%252F%252Fmain%2520function%250Aasync%2520function%2520main()%257B%250A%2509await%2520wrapperFnWait(%2522hello%2522)%253B%250A%2509wrapperFnDirect(%2522hello2%2522)%253B%250A%257D%250Amain()%253B))
```js
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @formatting pretty_print
// @language_in ES_NEXT
// @language_out ES_NEXT
// @debug true
// ==/ClosureCompiler==
//async functions
async function waitLog(message){
console.log(message);
}
async function wrapperFnWait(message){
await waitLog(message);
}
//synchronous functions
function directLog(message){
console.log(message);
}
function wrapperFnDirect(message){
directLog(message);
}
//main function
async function main(){
await wrapperFnWait("hello");
wrapperFnDirect("hello2");
}
main();
```
This is the result:
```js
'use strict';
async function $waitLog$$() {
console.log("hello");
}
async function $wrapperFnWait$$() {
await $waitLog$$();
}
(async function() {
await $wrapperFnWait$$();
console.log("hello2");
})();
```
The `wrapperFnDirect()` and `directLog()` functions get completely inlined so it simply becomes `console.log("hello2");`.
But `wrapperFnWait()` and `waitLog()` leave behind a lot of code that seems like it could be reduced further.
Contributor guide
Assessment
This issue has not been assessed yet.