Destructuring an object with a string computed property throws an error
See original GitHub issueGiven the current test case:
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// @language_in ECMASCRIPT6_STRICT
// @language_out ECMASCRIPT6_STRICT
// ==/ClosureCompiler==
var React = require("react");
var {
["useState"]: useState
} = React;
function NameComponent() {
const [name] = useState("Ben");
return React.createElement("div", null, name);
}
module.exports = NameComponent;
The following error is thrown:
23: java.lang.UnsupportedOperationException: COMPUTED_PROP 4 [length: 22] [source_file: Input_0] is not a string node
at com.google.javascript.rhino.Node.getString(Node.java:1226)
at com.google.javascript.jscomp.AnalyzePrototypeProperties$ProcessProperties.visit(AnalyzePrototypeProperties.java:324)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:855)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:967)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:851)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:967)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:851)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:967)
at com.google.javascript.jscomp.NodeTraversal.handleScript(NodeTraversal.java:805)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:830)
at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:967)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:851)
at com.google.javascript.jscomp.NodeTraversal.traverse(NodeTraversal.java:336)
at com.google.javascript.jscomp.NodeTraversal.traverse(NodeTraversal.java:346)
at com.google.javascript.jscomp.AnalyzePrototypeProperties.process(AnalyzePrototypeProperties.java:158)
at com.google.javascript.jscomp.CrossChunkMethodMotion.process(CrossChunkMethodMotion.java:92)
at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:310)
at com.google.javascript.jscomp.PhaseOptimizer$Loop.process(PhaseOptimizer.java:455)
at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:231)
at com.google.javascript.jscomp.Compiler.performOptimizations(Compiler.java:2459)
at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:843)
at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:839)
at com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread(CompilerExecutor.java:129)
at com.google.javascript.jscomp.Compiler.runInCompilerThread(Compiler.java:871)
at com.google.javascript.jscomp.Compiler.stage2Passes(Compiler.java:838)
at com.google.javascript.jscomp.Compiler.compile(Compiler.java:734)
at com.google.javascript.jscomp.webservice.backend.CompilerInvokerImpl.compile(CompilerInvokerImpl.java:46)
at com.google.javascript.jscomp.webservice.backend.ServerController.executeRequest(ServerController.java:181)
at com.google.javascript.jscomp.webservice.backend.CompilationRequestHandler.serviceParsedRequest(CompilationRequestHandler.java:180)
at com.google.javascript.jscomp.webservice.backend.CompilationRequestHandler.service(CompilationRequestHandler.java:162)
at com.google.javascript.jscomp.webservice.frontend.CompilationServlet.doPost(CompilationServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1772)
at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at com.google.apphosting.runtime.jetty9.ParseBlobUploadHandler.handle(ParseBlobUploadHandler.java:119)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1182)
at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doHandle(AppEngineWebAppContext.java:171)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:296)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:539)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333)
at com.google.apphosting.runtime.jetty9.RpcConnection.handle(RpcConnection.java:202)
at com.google.apphosting.runtime.jetty9.RpcConnector.serviceRequest(RpcConnector.java:81)
at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:123)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:699)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:661)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:631)
at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run(JavaRuntime.java:825)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:273)
at java.lang.Thread.run(Thread.java:745)
Original Post Data:
output_format=json&output_info=compiled_code&output_info=warnings&output_info=errors&output_info=statistics&compilation_level=ADVANCED_OPTIMIZATIONS&warning_level=verbose&language_out=ECMASCRIPT6_STRICT&output_file_name=default.js&js_code=var%20React%20%3D%20require(%22react%22)%3B%0A%0Avar%20%7B%0A%20%20%5B%22useState%22%5D%3A%20useState%0A%7D%20%3D%20React%3B%0A%0Afunction%20Component_ComputeFunction()%20%7B%0A%20%20const%20%5Bname%5D%20%3D%20useState(%22Ben%22)%3B%0A%20%20return%20React.createElement(%22div%22%2C%20null%2C%20name)%3B%0A%7D%0A%0Avar%20Component%20%3D%20%2F%2F%20Component%20OPCODES%0A%5B1%20%2F%2F%20COMPONENT_WITH_HOOKS%0A%2C%202%20%2F%2F%20DISPLAY_NAME%0A%2C%20%22Component%22%2C%203%20%2F%2F%20ROOT_PROPS_SHAPE%0A%2C%20null%2C%2020%20%2F%2F%20UNCONDITIONAL_TEMPLATE%0A%2C%20%5B7%20%2F%2F%20OPEN_ELEMENT_DIV%0A%2C%2042%20%2F%2F%20ELEMENT_DYNAMIC_TEXT_CHILD%0A%2C%200%2C%2042%20%2F%2F%20ELEMENT_DYNAMIC_TEXT_CHILD%0A%2C%201%2C%209%20%2F%2F%20CLOSE_ELEMENT%0A%5D%2C%20Component_ComputeFunction%5D%3B%0Amodule%5B%22exports%22%5D%20%3D%20Component%3B
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Why does object destructuring assignment throw an error ...
I understand that the template string could be defined as a variable beforehand and then passed using computed property brackets, but I'm just ......
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >10. Destructuring - Exploring JS
Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and Arrays. It can be used in...
Read more >Destructuring and parameter handling in ECMAScript 6 - 2ality
ECMAScript 6 (ES6) supports destructuring, a convenient way to extract values from data stored in (possibly nested) objects and arrays.
Read more >Prevent Error with Default {} when Destructuring
When you use destructuring, make sure to set a default value of empty {} to prevent it from throwing an error! function hi(person)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@trueadm I’ve submitted a fix for the crash internally. It will be pushed to GitHub tomorrow.
@lauraharker Thank you 😃