You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser gives AND and OR the same precedence, but the device evaluates AND first #1994
The parser gives and and or the same precedence and groups them left to right. On the device, and binds tighter than or (Roku's precedence table lists them as AND > OR). So for
x=aorbandc
the device evaluates a or (b and c), but BrighterScript's AST is (a or b) and c:
const{ Parser }=require('brighterscript');constp=Parser.parse('sub main()\n x = a or b and c\nend sub');constexpr=p.ast.statements[0].func.body.statements[0].value;constshow=e=>e.left ? `(${show(e.left)}${e.operator.text}${show(e.right)})` : e.name?.text??e.token?.text;console.log(show(expr));// ((a or b) and c)
The cause is in Parser.boolean(), which matches TokenKind.And and TokenKind.Or in one loop.
Plain transpiling is unaffected, because the original tokens are written back out as they were. It bites plugins that rebuild expressions from the AST. With rooibos 5.17.0 code coverage on, every operand of an and/or gets wrapped in a function call, and the wrapping follows the AST grouping. So this:
is instrumented as (content = invalid or content.video = invalid) and isReady. That evaluates content.video when content is invalid, and the coverage build crashes where the normal build doesn't. We worked around it by adding explicit parentheses to the two places in our code that relied on the device's grouping.
Splitting boolean() into an or level that calls an and level would match the device.
Activity