Skip to content

Conversation

@Perryvw
Copy link
Member

@Perryvw Perryvw commented Apr 26, 2021

Fixes #967

@Perryvw Perryvw requested review from lolleko and tomblind April 26, 2021 20:04
@Perryvw Perryvw self-assigned this Apr 26, 2021

// Starting from the back, concatenating ifs into one big if/elseif statement
const concatenatedIf = caseClauses.reduceRight((previousCondition, clause, index) => {
const concatenatedIf = statement.caseBlock.clauses.reduceRight((previousCondition, clause, index) => {
Copy link
Member

Choose a reason for hiding this comment

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

Not, related to this PR. But I find this reduceRight call extremely hard to read. If you want to you can refactor it. maybe by splitting the generation of the statements and the concatenation of the statements?

const ifStatementsForCases = statement.caseBlock.clauses.filter(!ts.isDefaultClause(clause)).map(
    ...
    return lua.createIfStatement(condition, lua.createBlock([goto])));
);
const concatenatedIf = ifStatementsForCases.reduceRight((prev, ifStatement) => {
    prev.elseBlock = ifStatement;
    return ifStatement;
});

If not, I am fine with merging the PR as it is.

@Perryvw Perryvw merged commit a617faf into master Apr 28, 2021
@Perryvw Perryvw deleted the bugfix/switch-default branch April 28, 2021 18:59
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.

default should be last case in switch statement

2 participants