@@ -250,6 +250,22 @@ public enum IdContext {
250250 /** An identifier that declares a variable and a namespace. */
251251 varAndNamespaceDecl ,
252252
253+ /**
254+ * An identifier that occurs in a type-only import.
255+ *
256+ * These may declare a type and/or a namespace, but for compatibility with our AST,
257+ * must be emitted as a VarDecl (with no variable binding).
258+ */
259+ typeOnlyImport ,
260+
261+ /**
262+ * An identifier that occurs in a type-only export.
263+ *
264+ * These may refer to a type and/or a namespace, but for compatibility with our AST,
265+ * must be emitted as an ExportVarAccess (with no variable binding).
266+ */
267+ typeOnlyExport ,
268+
253269 /** An identifier that declares a variable, type, and namepsace. */
254270 varAndTypeAndNamespaceDecl ,
255271
@@ -278,7 +294,8 @@ public enum IdContext {
278294 * True if this occurs as part of a type annotation, i.e. it is {@link #typeBind} or {@link
279295 * #typeDecl}, {@link #typeLabel}, {@link #varInTypeBind}, or {@link #namespaceBind}.
280296 *
281- * <p>Does not hold for {@link #varAndTypeDecl}.
297+ * <p>Does not hold for {@link #varAndTypeDecl} or {@link #typeOnlyImportExport} as these
298+ * do not occur in type annotations.
282299 */
283300 public boolean isInsideType () {
284301 return this == typeBind
@@ -488,6 +505,14 @@ public Label visit(Identifier nd, Context c) {
488505 addVariableBinding ("decl" , key , name );
489506 addNamespaceBinding ("namespacedecl" , key , name );
490507 break ;
508+ case typeOnlyImport :
509+ addTypeBinding ("typedecl" , key , name );
510+ addNamespaceBinding ("namespacedecl" , key , name );
511+ break ;
512+ case typeOnlyExport :
513+ addTypeBinding ("typebind" , key , name );
514+ addNamespaceBinding ("namespacebind" , key , name );
515+ break ;
491516 case varAndTypeAndNamespaceDecl :
492517 addVariableBinding ("decl" , key , name );
493518 addTypeBinding ("typedecl" , key , name );
@@ -1538,7 +1563,14 @@ public Label visit(ExportNamedDeclaration nd, Context c) {
15381563 Label lbl = super .visit (nd , c );
15391564 visit (nd .getDeclaration (), lbl , -1 );
15401565 visit (nd .getSource (), lbl , -2 );
1541- visitAll (nd .getSpecifiers (), lbl , nd .hasSource () ? IdContext .label : IdContext .export , 0 );
1566+ IdContext childContext =
1567+ nd .hasSource () ? IdContext .label :
1568+ nd .hasTypeKeyword () ? IdContext .typeOnlyExport :
1569+ IdContext .export ;
1570+ visitAll (nd .getSpecifiers (), lbl , childContext , 0 );
1571+ if (nd .hasTypeKeyword ()) {
1572+ trapwriter .addTuple ("hasTypeKeyword" , lbl );
1573+ }
15421574 return lbl ;
15431575 }
15441576
@@ -1554,16 +1586,20 @@ public Label visit(ExportSpecifier nd, Context c) {
15541586 public Label visit (ImportDeclaration nd , Context c ) {
15551587 Label lbl = super .visit (nd , c );
15561588 visit (nd .getSource (), lbl , -1 );
1557- visitAll (nd .getSpecifiers (), lbl );
1589+ IdContext childContext = nd .hasTypeKeyword () ? IdContext .typeOnlyImport : IdContext .varAndTypeAndNamespaceDecl ;
1590+ visitAll (nd .getSpecifiers (), lbl , childContext , 0 );
15581591 emitNodeSymbol (nd , lbl );
1592+ if (nd .hasTypeKeyword ()) {
1593+ trapwriter .addTuple ("hasTypeKeyword" , lbl );
1594+ }
15591595 return lbl ;
15601596 }
15611597
15621598 @ Override
15631599 public Label visit (ImportSpecifier nd , Context c ) {
15641600 Label lbl = super .visit (nd , c );
15651601 visit (nd .getImported (), lbl , 0 , IdContext .label );
1566- visit (nd .getLocal (), lbl , 1 , IdContext . varAndTypeAndNamespaceDecl );
1602+ visit (nd .getLocal (), lbl , 1 , c . idcontext );
15671603 return lbl ;
15681604 }
15691605
0 commit comments