Can't compile async function with library injection disabled
Sample input code:
(async function(){})()
Expected output: it compiles Actual output:
liam$ java -jar /usr/lib/node_modules/google-closure-compiler/compiler.jar --inject_libraries=false <<< '(async function(){})()'
The compiler is waiting for input via stdin.
java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.
Unexpected variable $jscomp
Node(NAME $jscomp): stdin:1:17
(async function(){})()
Parent(GETPROP): stdin:1:17
(async function(){})()
at com.google.javascript.jscomp.VarCheck.visit(VarCheck.java:207)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:730)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBlockScope(NodeTraversal.java:817)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:724)
at com.google.javascript.jscomp.NodeTraversal.traverseFunction(NodeTraversal.java:761)
at com.google.javascript.jscomp.NodeTraversal.handleFunction(NodeTraversal.java:692)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:708)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.handleScript(NodeTraversal.java:680)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:705)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
at com.google.javascript.jscomp.NodeTraversal.traverseRoots(NodeTraversal.java:325)
at com.google.javascript.jscomp.VarCheck.process(VarCheck.java:145)
at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:307)
at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:233)
at com.google.javascript.jscomp.Compiler.performOptimizations(Compiler.java:2459)
at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:844)
at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:840)
at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:93)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unexpected variable $jscomp
... 35 more
Yes, the libraries are needed for transpilation of many features. Why do you want to use --inject_libraries=false?
Regardless of my motives for not wanting libraries injected, I would at least expect closure-compiler not to crash when using async/await under this flag.
As I recall, that flag was only intended to be used in some rare cases. Any time you can get the compiler to crash, it's a valid and helpful bug report. It's just a question of prioritization.
Presumably we could handle this by adding an extern /** @type {?} */ var $jscomp; instead of injecting anything if --inject_libraries=false.
If we added the option to the online debugger then we could have the added benefit of not outputting lots of extra junk when we're not interested in that part of the compile.
Presumably we could handle this by adding an extern
/** @type {?} */ var $jscomp;instead of injecting anything if--inject_libraries=false.
I tried appending that to scripts that I compile with --inject_libraries=false and it worked!
I also tried this as a workaround and it did also work.
"[{\"src\":\"/** @externs */\\n\\n/** @type {?} */ var $jscomp\",\"path\":\"externs/jscomp.js\"},{\"src\":\"async function foo(){};foo()\",\"path\":\"foo.js\"}]"
I use the closure compiler to minify individual JavaScript files because I need to do the code splitting dynamically at run time.
I just want to leverage the compiler to minify (and transplie) individual JavaScript files to different targets. Please don't forget about this use case. Even if the compiler was designed to be used in a certain way for maximum effect, I think it can do a lot of good when used as a component like this but I need this bit of modularity for that to work.
When the vscomp runtime is included in every file it adds so much weight. What I want to do in this case is that I use force inject to include the runtime in my entry point and I then compile everything else with --inject_libraries=false.
I have my workarounds, but I just wanted to say thanks for an awesome tool and please don't forget that people like me exist that use the compiler without the closure library.