Repository: google/closure-compiler
Issue: Unlike var statements, const statements do not support multiple types

Code -

```
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// @language ECMASCRIPT6_STRICT
// ==/ClosureCompiler==
"use strict";
const
  /** @const {string} */ foo = "1",
  /** @const {number} */ bar = 1;

const
  /** @type {string} */ baz = "1",
  /** @type {number} */ taz = 1;
```

Warnings -

```
JSC_MULTIPLE_VAR_DEF: declaration of multiple variables with shared type information at line 2 character 0
const
^
JSC_MULTIPLE_VAR_DEF: declaration of multiple variables with shared type information at line 6 character 0
const
^
```

Note - changing them to `var` avoids the warnings, of course.


Changed files:
test/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclarationTest.java, src/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclaration.java

diff --git a/src/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclaration.java b/src/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclaration.java
index 291ff9a2e..bf678d067 100644
--- a/src/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclaration.java
+++ b/src/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclaration.java
@@ -132,17 +132,26 @@ public final class Es6RewriteBlockScopedDeclaration extends AbstractPostOrderCal
     if (!letConsts.isEmpty()) {
       for (Node n : letConsts) {
         if (n.isConst()) {
-          JSDocInfo existingInfo = n.getJSDocInfo();
-          if (existingInfo == null) {
-            existingInfo = n.getFirstChild().getJSDocInfo();
-            n.getFirstChild().setJSDocInfo(null);
+          // Normalize declarations like "const x = 1, y = 2;" so that inline
+          // type annotations are preserved.
+          for (Node child : n.children()) {
+            Node declaration = IR.var(child.detachFromParent());
+            declaration.useSourceInfoFrom(n);
+            JSDocInfo existingInfo = n.getJSDocInfo();
+            if (existingInfo == null) {
+              existingInfo = child.getJSDocInfo();
+              child.setJSDocInfo(null);
+            }
+            JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(existingInfo);
+            builder.recordConstancy();
+            JSDocInfo info = builder.build();
+            declaration.setJSDocInfo(info);
+            n.getParent().addChildAfter(declaration, n);
           }
-          JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(existingInfo);
-          builder.recordConstancy();
-          JSDocInfo info = builder.build();
-          n.setJSDocInfo(info);
+          n.detachFromParent();
+        } else {
+          n.setType(Token.VAR);
         }
-        n.setType(Token.VAR);
       }
       compiler.reportCodeChange();
     }
diff --git a/test/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclarationTest.java b/test/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclarationTest.java
index fcc8c663c..270c277b4 100644
--- a/test/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclarationTest.java
+++ b/test/com/google/javascript/jscomp/Es6RewriteBlockScopedDeclarationTest.java
@@ -778,6 +778,10 @@ public final class Es6RewriteBlockScopedDeclarationTest extends CompilerTestCase
     testWarning("/** @type {number} */ const x = 'str';", TypeValidator.TYPE_MISMATCH_WARNING);
     testWarning("const /** number */ x = 'str';", TypeValidator.TYPE_MISMATCH_WARNING);
     testWarning("const /** @type {number} */ x = 'str';", TypeValidator.TYPE_MISMATCH_WARNING);
+    testWarning("const /** @type {string} */ x = 3, /** @type {number} */ y = 3;",
+        TypeValidator.TYPE_MISMATCH_WARNING);
+    testWarning("const /** @type {string} */ x = 'str', /** @type {string} */ y = 3;",
+        TypeValidator.TYPE_MISMATCH_WARNING);
   }
 
   public void testDoWhileForOfCapturedLetAnnotated() {