diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index d997ab95eb..58fdb81c03 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -482,6 +482,15 @@ export class Assembler implements Emitter { LOG.trace(`Processing enum: ${colors.gray(namespace.join('.'))}.${colors.cyan(type.symbol.name)}`); } + const decl = type.symbol.valueDeclaration; + const flags = ts.getCombinedModifierFlags(decl); + // tslint:disable-next-line:no-bitwise + if (flags & ts.ModifierFlags.Const) { + this._diagnostic(decl, + ts.DiagnosticCategory.Error, + `Exported enum cannot be declared 'const'`); + } + const jsiiType: spec.EnumType = { assembly: this.projectInfo.name, fqn: `${[this.projectInfo.name, ...namespace].join('.')}.${type.symbol.name}`, diff --git a/packages/jsii/test/negatives/neg.const-enum.ts b/packages/jsii/test/negatives/neg.const-enum.ts new file mode 100644 index 0000000000..bc3a792ba4 --- /dev/null +++ b/packages/jsii/test/negatives/neg.const-enum.ts @@ -0,0 +1,8 @@ +///!MATCH_ERROR: Exported enum cannot be declared 'const' + +export const enum NotAllowed { + ThisEnum, + GetsInlined, + AndSoItGetsLost, + ForJsii +} \ No newline at end of file