Repository: google/closure-compiler (java)

Issue:
closure compiler crashes for some es6 input
```js
var z = require('./node_1')

function fib(n){
    "use strict";
    if(n===0||n===1){
        return 1
    } else{
        return fib(n-1) + fib(n-2)
    }
}
module.exports = {
    used2 (x) {
        "use strict";
        return z.used1(3,x)
    },
    fib // works with : fib
}
```

```
java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.

null
  Node(SCRIPT): node_2.js:4:0
var z = require('./node_1')
  Parent: NULL
        at com.google.javascript.jscomp.ProcessCommonJSModules$ProcessCommonJsModulesCallback.processExports(ProcessCommonJSModules.java:39\
6)
        at com.google.javascript.jscomp.ProcessCommonJSModules$ProcessCommonJsModulesCallback.visitScript(ProcessCommonJSModules.java:299)
        at com.google.javascript.jscomp.ProcessCommonJSModules$ProcessCommonJsModulesCallback.visit(ProcessCommonJSModules.java:235)
        at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:611)
        at com.google.javascript.jscomp.NodeTraversal.traverse(NodeTraversal.java:297)
        at com.google.javascript.jscomp.NodeTraversal.traverseEs6(NodeTraversal.java:562)
        at com.google.javascript.jscomp.ProcessCommonJSModules.process(ProcessCommonJSModules.java:85)
        at com.google.javascript.jscomp.Compiler.processAMDAndCommonJSModules(Compiler.java:1493)
	at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1299)
        at com.google.javascript.jscomp.Compiler.parse(Compiler.java:704)
        at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:665)
        at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:89)
        at com.google.javascript.jscomp.Compiler$2.call(Compiler.java:636)
        at com.google.javascript.jscomp.Compiler$2.call(Compiler.java:633)
        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.NullPointerException
```

Pull request description:
Allow es6 object shorthand in commonjs module exports
Fixes #1224

Allows CommonJS module exports to use ES6 object literal shorthand syntax:

```JavaScript
var foo = 'bar';
module.exports = {
  foo,
  foobar() { console.log(foo); }
}
```

Patch:
diff --git a/src/com/google/javascript/jscomp/ProcessCommonJSModules.java b/src/com/google/javascript/jscomp/ProcessCommonJSModules.java
index b18ad6379..2e21df2fe 100644
--- a/src/com/google/javascript/jscomp/ProcessCommonJSModules.java
+++ b/src/com/google/javascript/jscomp/ProcessCommonJSModules.java
@@ -392,10 +392,11 @@ public final class ProcessCommonJSModules implements CompilerPass {
               .createScope(script, null);
           for (Node key = rhsValue.getFirstChild();
                key != null; key = key.getNext()) {
-            if (key.getJSDocInfo() == null
-                && key.getFirstChild().isName()) {
-              Var aliasedVar =
-                  globalScope.getVar(key.getFirstChild().getString());
+            if (key.getJSDocInfo() == null &&
+                (key.getFirstChild() == null || key.getFirstChild().isName())) {
+              String aliasedVarName = key.getFirstChild() == null ?
+                  key.getString() : key.getFirstChild().getString();
+              Var aliasedVar = globalScope.getVar(aliasedVarName);
               JSDocInfo info =
                   aliasedVar == null ? null : aliasedVar.getJSDocInfo();
               if (info != null &&


Test patch:
diff --git a/test/com/google/javascript/jscomp/ProcessCommonJSModulesTest.java b/test/com/google/javascript/jscomp/ProcessCommonJSModulesTest.java
index 41adea1ae..228b57c4b 100644
--- a/test/com/google/javascript/jscomp/ProcessCommonJSModulesTest.java
+++ b/test/com/google/javascript/jscomp/ProcessCommonJSModulesTest.java
@@ -225,7 +225,32 @@ public final class ProcessCommonJSModulesTest extends CompilerTestCase {
         "goog.provide('module$test');" +
         "var foobar$$module$test = {foo: 'bar'};" +
         "module$test = foobar$$module$test;");
-}
+  }
+
+  public void testEs6ObjectShorthand() {
+    setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT6,
+        CompilerOptions.LanguageMode.ECMASCRIPT5);
+    setFilename("test");
+    testModules(
+        "function foo() {}"
+            + "module.exports = {"
+            + "  prop: 'value',"
+            + "  foo"
+            + "}",
+        "goog.provide('module$test');"
+            + "function foo$$module$test() {}"
+            + "module$test = { prop: 'value', foo }");
+
+    testModules(
+        "module.exports = {\n"
+            + "  prop: 'value',\n"
+            + "  foo() {\n"
+            + "    console.log('bar');\n"
+            + "  }\n"
+            + "};",
+        "goog.provide('module$test');"
+            + "module$test = { prop: 'value', foo() { console.log('bar'); }}" );
+  }
 
   public void testSortInputs() throws Exception {
     SourceFile a = SourceFile.fromCode("a.js", "require('b');require('c')");