Repository: google/closure-compiler (java)

Issue:
Crash using enhanced object literals in goog.module exports
### Short property "x" in exports here:
``` javascript
goog.module("test");

var x = {
  a: 5,
  b: 6
};

exports = {
  x
};
```

```
	at com.google.javascript.jscomp.ClosureRewriteModule.maybeUpdateExportDeclToNode(ClosureRewriteModule.java:366)
	at com.google.javascript.jscomp.ClosureRewriteModule.maybeUpdateExportObjectDecl(ClosureRewriteModule.java:353)
	at com.google.javascript.jscomp.ClosureRewriteModule.visit(ClosureRewriteModule.java:320)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:607)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
	at com.google.javascript.jscomp.NodeTraversal.traverse(NodeTraversal.java:299)
	at com.google.javascript.jscomp.NodeTraversal.traverseEs6(NodeTraversal.java:558)
	at com.google.javascript.jscomp.ClosureRewriteModule.hotSwapScript(ClosureRewriteModule.java:131)
	at com.google.javascript.jscomp.ClosureRewriteModule.process(ClosureRewriteModule.java:125)
	at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:285)
	at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:217)
	at com.google.javascript.jscomp.Compiler.check(Compiler.java:769)
```

https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.module(%2522test%2522)%253B%250A%250Avar%2520x%2520%253D%2520%257B%250A%2520%2520a%253A%25205%252C%250A%2520%2520b%253A%25206%250A%257D%253B%250A%250Aexports%2520%253D%2520%257B%250A%2520%2520x%250A%257D%253B%250A%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1

### Workaround: don't use short property
``` javascript
exports = {
  x: x
};
```
https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.module(%2522test%2522)%253B%250A%250Avar%2520x%2520%253D%2520%257B%250A%2520%2520a%253A%25205%252C%250A%2520%2520b%253A%25206%250A%257D%253B%250A%250Aexports%2520%253D%2520%257B%250A%2520%2520x%253A%2520x%250A%257D%253B%250A%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1

Pull request description:
Support shorthand field in exported object literal in ClosureRewriteModule
Fixed it so that "exports = {x}" is treated as "exports = {x: x}".

Report an error if goog.module exports contain computed properties.

Fixes #1142 

Patch:
diff --git a/src/com/google/javascript/jscomp/ClosureRewriteModule.java b/src/com/google/javascript/jscomp/ClosureRewriteModule.java
index 1fc360b0d..a0854193a 100644
--- a/src/com/google/javascript/jscomp/ClosureRewriteModule.java
+++ b/src/com/google/javascript/jscomp/ClosureRewriteModule.java
@@ -83,6 +83,11 @@ final class ClosureRewriteModule implements NodeTraversal.Callback, HotSwapCompi
           "JSC_GOOG_MODULE_INVALID_GET_ALIAS",
           "goog.module.get should not be aliased.");
 
+  static final DiagnosticType INVALID_EXPORT_COMPUTED_PROPERTY =
+      DiagnosticType.error(
+          "JSC_GOOG_MODULE_INVALID_EXPORT_COMPUTED_PROPERTY",
+          "Computed properties are not yet supported in goog.module exports.");
+
   private final AbstractCompiler compiler;
 
   private class ModuleDescription {
@@ -348,8 +353,10 @@ final class ClosureRewriteModule implements NodeTraversal.Callback, HotSwapCompi
 
     if (rhs.isObjectLit()) {
       for (Node c = rhs.getFirstChild(); c != null; c = c.getNext()) {
-        if (c.isStringKey()) {
-          Node value = c.getFirstChild();
+        if (c.isComputedProp()) {
+          t.report(c, INVALID_EXPORT_COMPUTED_PROPERTY);
+        } else if (c.isStringKey()) {
+          Node value = c.hasChildren() ? c.getFirstChild() : IR.name(c.getString());
           maybeUpdateExportDeclToNode(t, c, value);
         }
       }


Test patch:
diff --git a/test/com/google/javascript/jscomp/ClosureRewriteModuleTest.java b/test/com/google/javascript/jscomp/ClosureRewriteModuleTest.java
index ae1bf8868..895e2c312 100644
--- a/test/com/google/javascript/jscomp/ClosureRewriteModuleTest.java
+++ b/test/com/google/javascript/jscomp/ClosureRewriteModuleTest.java
@@ -396,6 +396,22 @@ public final class ClosureRewriteModuleTest extends Es6CompilerTestCase {
         + "});");
   }
 
+  public void testExportEnhancedObjectLiteral() {
+    testEs6(
+        "goog.module('ns.a');" +
+        "exports = { something };",
+
+        "goog.provide('ns.a');" +
+        "goog.scope(function(){" +
+        "  /** @const */ ns.a = { /** @const */ something };" +
+        "});");
+
+    testErrorEs6(
+        "goog.module('ns.a');" +
+        "exports = { [something]: 3 };",
+        ClosureRewriteModule.INVALID_EXPORT_COMPUTED_PROPERTY);
+  }
+
   public void testRequiresRetainOrder() {
     test(
         "goog.module('ns.a');" +