-
Notifications
You must be signed in to change notification settings - Fork 47
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
Don't include namespaces when transpiling ternary / null coalescing expressions #571
Comments
Closing as duplicate of #678 |
@TwitchBronBron Check this example
It will be transpiled to IIFE where null coalescing operator could be fixed same way. |
@przemekborowski we definitely have some cleanup to do around some of these captures. Our transpiler is a bit "dumb" and doesn't really know a lot about the variables it's capturing. With the upcoming type tracking work in #815 we should hopefully have more detailed type information about the variables we're capturing so we can properly handle passing in
|
|
You're right. :) I was just trying to explain that we need to avoid executing the alternate in the As of right now, we do only pass
The problem is, The ternary code is here: brighterscript/src/parser/Expression.ts Line 1341 in 995a564
And the core logic for collecting the expression info is here: Line 1137 in 995a564
Once #815 lands, we should be able to update that function to leverage the SymbolTable to do a better job determining which items are actually namespaces and thus actually pass in their transpiled/resolved states to the IIFE. |
Exactly brighterscript/src/util.ts is a place where it could be fixed IMO even now, following change could fix it (I haven't done extensive testing though):
and add condition to wrap expressionWalker:
plus some cleanup inside I can prepare PR with that if you want to follow that path. |
You're welcome to start working on this to see if you can come up with a solution, sure! However, I don't think this specific suggestion will work. The BrighterScript AST stores expressions backwards. So for: alpha.beta.charlie() 'assume `alpha.beta` are namespaces This is the AST structure: new CallExpression(
[/*args*/],
new DottedGetExpression(
"charlie",
new DottedGetExpression(
"beta",
new VariableExpression("alpha")
)
)
)
So you can't just skip the walk, because you'll rarely start with But please feel free to play around with the codebase to see how it's working. |
ternary and null coalescing expressions are incorrectly "capturing" namespace names for the non-simple statements. We should do a better job filtering those out. (
Math
should not be sent as a parameter)The text was updated successfully, but these errors were encountered: