prebirth: Wrap `if' applications

* build-aux/bootstrap/prebirth.js (fnmap)[if]: Wrap generated code
    in self-executing function.
master
Mike Gerwitz 2017-08-30 00:14:45 -04:00
parent dcc6aed322
commit 59daf7a5b5
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 6 additions and 3 deletions

View File

@ -543,10 +543,13 @@ class Compiler
const fnmap = { const fnmap = {
'js:console': 'console.log', 'js:console': 'console.log',
// simple if statement with optional else // simple if statement with optional else, wrapped in a self-executing
// function to simplify code generation (e.g. returning an if)
'if': ( [ pred, t, f ], stoes ) => 'if': ( [ pred, t, f ], stoes ) =>
`if (${stoes(pred)}) {${stoes(t)};} ` + "(function(){" +
( ( f === undefined ) ? '' : `else {${stoes(f)};}` ), `if (${stoes(pred)}){return ${stoes(t)};}` +
( ( f === undefined ) ? '' : `else{return ${stoes(f)};}` ) +
"})()",
// (let ((binding val) ...) ...body), compiled as a self-executing // (let ((binding val) ...) ...body), compiled as a self-executing
// function which allows us to easily represent the return value of the // function which allows us to easily represent the return value of the