Closed
Description
Tested with Closure Compiler v20200517
Command: java -jar closure-compiler.jar --js in.js --js_output_file out.js --language_out ECMASCRIPT_2019
in.js:
window.Class = class {
constructor()
{
let newTarget = new.target;
return Object.create(newTarget.prototype);
}
};
This crashes with IllegalStateException
(full stack omitted for brevity):
java.lang.IllegalStateException: Unexpected expression node: NEW_TARGET 4 [length: 10] [source_file: in.js]
parent:NAME newTarget 4 [length: 22] [source_file: in.js] [constant_var_flags: 2]
at com.google.javascript.jscomp.NodeUtil.evaluatesToLocalValue(NodeUtil.java:4754)
at com.google.javascript.jscomp.RemoveUnusedCode$NameDeclarationStatement.isAssignedValueLocal(RemoveUnusedCode.java:2384)
at com.google.javascript.jscomp.RemoveUnusedCode$VarInfo.addRemovable(RemoveUnusedCode.java:2670)
at com.google.javascript.jscomp.RemoveUnusedCode.traverseDeclarationStatement(RemoveUnusedCode.java:1038)
Another seemingly related case is the following:
window.Class = class {
constructor()
{
return new.target;
}
};
This crashes too but only in ADVANCED compilation mode. Full command line:
java -jar closure-compiler.jar --js in.js --js_output_file out.js --language_out ECMASCRIPT_2019 --compilation_level ADVANCED
This crashes with INTERNAL COMPILER ERROR
(full stack omitted for brevity):
in.js:4: WARNING - [JSC_TYPE_MISMATCH] inconsistent return type
found : Function
required: window.Class
return new.target;
^^^^^^^^^^
0 error(s), 1 warning(s), 100.0% typed
java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.
Unexpected expression node: NEW_TARGET 4 [length: 10] [source_file: in.js] : Function
parent:RETURN 4 [length: 18] [source_file: in.js]
Node(RETURN): in.js:4:2
return new.target;
Parent(BLOCK): in.js:3:1
{
at com.google.javascript.jscomp.NodeUtil.evaluatesToLocalValue(NodeUtil.java:4754)
at com.google.javascript.jscomp.PureFunctionIdentifier$FunctionBodyAnalyzer.updateSideEffectsForNode(PureFunctionIdentifier.java:829)
at com.google.javascript.jscomp.PureFunctionIdentifier$FunctionBodyAnalyzer.visit(PureFunctionIdentifier.java:709)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:909)