clutz icon indicating copy to clipboard operation
clutz copied to clipboard

Exported enum from goog.module() breaks Clutz

Open SLaks opened this issue 8 years ago • 1 comments

JS:

goog.module('hr.util.TriState');
goog.module.declareLegacyNamespace();

/**
 * Representation of a tri-state boolean.
 * @enum {string}
 */
const TriState = {
  UNKNOWN: 'UNKNOWN',
  FALSE: 'FALSE',
  TRUE: 'TRUE',
};

exports = TriState;

Clutz generates:

declare namespace ಠ_ಠ.clutz.hr.util {
  //!! hr.util.TriState aliases enum module$contents$hr$util$TriState_TriState
  type TriState = module$contents$hr$util$TriState_TriState ;
  const TriState : typeof module$contents$hr$util$TriState_TriState ;
}
declare module 'goog:hr.util.TriState' {
  import TriState = ಠ_ಠ.clutz.hr.util.TriState;
  export default TriState;
}

This does not work at all.

Assigning the enum object directly to exports in the JS fixes, and generates

declare namespace ಠ_ಠ.clutz.hr.util {
  /**
   * Representation of a tri-state boolean.
   */
  enum TriState {
    FALSE = 'FALSE' ,
    TRUE = 'TRUE' ,
    UNKNOWN = 'UNKNOWN' ,
  }
}
declare module 'goog:hr.util.TriState' {
  import TriState = ಠ_ಠ.clutz.hr.util.TriState;
  export default TriState;
}

SLaks avatar Sep 05 '18 21:09 SLaks

Clutz has issues with goog.module.declareLegacyNamespace(); you can also try removing that line, which I think would fix the issue too.

rkirov avatar Sep 08 '18 06:09 rkirov