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
ifdisplayGreeting {
letmessage="Enjoying the docs so far?"Js.log(message)
}
respective JS output in doc:
if(displayGreeting){console.log("Enjoying the docs so far?");}
When the starter project is cloned locally as described the ReScript snippet does not compile:
1 │ if displayGreeting {
2 │ let message = "Enjoying the docs so far?"
3 │ Js.log(message)
The value displayGreeting can't be found
FAILED: cannot make progress due to previous errors.
A similar result can also be observed in the playground linked from the ReScript snippet
When the ReScript snippet is fixed in the most obvious way the generated JS output does not match the documentation:
letdisplayGreeting=trueifdisplayGreeting {
letmessage="Enjoying the docs so far?"Js.log(message)
}
the actual JS generated output is (header and exports are omitted):
console.log("Enjoying the docs so far?");vardisplayGreeting=true;
To get the if statement in JS output the ReScript snippet could be modified to:
letdisplayGreeting=ref(true)
ifdisplayGreeting.contents {
letmessage="Enjoying the docs so far?"Js.log(message)
}
but the resulting JS output below still does not match the documention:
vardisplayGreeting={contents: true};if(displayGreeting.contents){console.log("Enjoying the docs so far?");}
The text was updated successfully, but these errors were encountered:
This example is more or less a symbolic to get the point across.. I am not sure if it would make much sense to add the extra noise.
Regarding the output: Since the boolean would be known during compile time, the compiler applies extra optimizations. For the correct output, you'd need to make displayGreeting an unknown external, or a function parameter etc:
@val external displayGreeting: bool = "displayGreeting"
if displayGreeting {
let message = "Enjoying the docs so far?"
Js.log(message)
}
this would compile to:
if (displayGreeting) {
console.log("Enjoying the docs so far?");
}
Documentation link:
https://rescript-lang.org/docs/manual/latest/let-binding#design-decisions
Current ReScript snippet in doc:
respective JS output in doc:
When the starter project is cloned locally as described the ReScript snippet does not compile:
A similar result can also be observed in the playground linked from the ReScript snippet
When the ReScript snippet is fixed in the most obvious way the generated JS output does not match the documentation:
the actual JS generated output is (header and exports are omitted):
To get the
if
statement in JS output the ReScript snippet could be modified to:but the resulting JS output below still does not match the documention:
The text was updated successfully, but these errors were encountered: