google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.35k stars 1.14k forks source link

Can't export enum directly (ES6 modules) #2260

Open supersteves opened 7 years ago

supersteves commented 7 years ago

Input 0

/** @enum {string} */
export default {
    CIRCLE: "circle",
    SQUARE: "square",
};

Input 1

import ShapeType from "./input0";
let /** ShapeType */ something = ShapeType.CIRCLE;

Error [debugger]:

input1:2: WARNING - Bad type annotation. Unknown type ShapeType$$module$input0
let /** ShapeType */ something = ShapeType.CIRCLE;

Workaround [debugger]:

/**
 * @enum {string}
 */
const ShapeType = {
    CIRCLE: "circle",
    SQUARE: "square",
};
export default ShapeType;

I think I've seen the same issue with export default class {...}, too.

ChadKillingsworth commented 7 years ago

I'm guessing this is due to commonjs module rewriting.

ChadKillingsworth commented 7 years ago

Whoops for some reason I saw this as CommonJS - not ES6.

dimvar commented 7 years ago

I see you are getting the warning even without NTI, so this isn't NTI specific.