Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsii): prohibit exported const enums #372

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return from there? So we don't include it in the .jsii assembly we'd create?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.


const jsiiType: spec.EnumType = {
assembly: this.projectInfo.name,
fqn: `${[this.projectInfo.name, ...namespace].join('.')}.${type.symbol.name}`,
Expand Down
8 changes: 8 additions & 0 deletions packages/jsii/test/negatives/neg.const-enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
///!MATCH_ERROR: Exported enum cannot be declared 'const'

export const enum NotAllowed {
ThisEnum,
GetsInlined,
AndSoItGetsLost,
ForJsii
}