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 bug with ternary transpile for indexed set #1357

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/bscPlugin/transpile/BrsFilePreTranspileProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class BrsFilePreTranspileProcessor {
}),
endIf: createToken(TokenKind.EndIf, 'end if', ternaryExpression.questionMarkToken.range)
});
} else if (isIndexedSetStatement(parent)) {
//if this is an indexedSetStatement, and the ternary expression is NOT an index
} else if (isIndexedSetStatement(parent) && parent.index !== ternaryExpression && !parent.additionalIndexes?.includes(ternaryExpression)) {
ifStatement = createIfStatement({
if: createToken(TokenKind.If, 'if', ternaryExpression.questionMarkToken.range),
condition: ternaryExpression.test,
Expand Down
21 changes: 21 additions & 0 deletions src/parser/tests/expression/TernaryExpression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,27 @@ describe('ternary expressions', () => {
);
});

it('supports ternary in indexedSet key', () => {
testTranspile(
`
sub main()
m[m.useAltKey ? m.altKey : m.key] = 1
end sub
`,
`
sub main()
m[(function(__bsCondition, m)
if __bsCondition then
return m.altKey
else
return m.key
end if
end function)(m.useAltKey, m)] = 1
end sub
`
TwitchBronBron marked this conversation as resolved.
Show resolved Hide resolved
);
});

it('supports scope-captured outer, and simple inner', () => {
testTranspile(
`
Expand Down
Loading