Skip to content

Fixed enums with identifier values not being supported.#392

Merged
Perryvw merged 5 commits intomasterfrom
feature/enum-update
Feb 11, 2019
Merged

Fixed enums with identifier values not being supported.#392
Perryvw merged 5 commits intomasterfrom
feature/enum-update

Conversation

@Perryvw
Copy link
Copy Markdown
Member

@Perryvw Perryvw commented Feb 10, 2019

Added reverse mapping for enums, allowing:

const myEnum {
    abc,
    def,
}
const x = myEnum.def; // x = 1
const y = myEnum[x]; // y = "def"

Also added support for constEnum["enumMemberName"] and refactored the const enum handling stuff a little.

Fixes #378 and closes #318

@Perryvw Perryvw requested review from lolleko and tomblind February 10, 2019 21:16
valueLiteral = tstl.createStringLiteral(member.initializer.text);
} else {
throw TSTLErrors.InvalidEnumMember(member.initializer);
valueExpression = tstl.createStringLiteral(member.initializer.text);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would it be better to use this.transformStringLiteral() here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, that is nicer. I also changed the numeric literal above this one to do the same.

@Perryvw Perryvw merged commit 5140ca8 into master Feb 11, 2019
@Perryvw Perryvw deleted the feature/enum-update branch February 11, 2019 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with initializing enums with identifiers Support reverse mappings for enums

2 participants