|
|
|
@ -34,6 +34,16 @@ let tmplImplicitContextTop = templateExpression(`
|
|
|
|
|
Object.assign({}, %%environment%%)
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
let tmplConditionalExpression = templateExpression(`
|
|
|
|
|
(() => {
|
|
|
|
|
if (%%condition%%) {
|
|
|
|
|
return %%consequence%%;
|
|
|
|
|
} else {
|
|
|
|
|
return %%alternative%%;
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
let implicitContextCounter = 0;
|
|
|
|
|
|
|
|
|
|
let trivial = {
|
|
|
|
@ -56,9 +66,10 @@ let trivial = {
|
|
|
|
|
},
|
|
|
|
|
NixIdentifier: (node, { getContext }) => {
|
|
|
|
|
// FIXME: Mangle reserved keywords like `const`
|
|
|
|
|
let safeName = (node.name === "import")
|
|
|
|
|
? "$import"
|
|
|
|
|
: node.name;
|
|
|
|
|
// let safeName = (node.name === "import")
|
|
|
|
|
// ? "$import"
|
|
|
|
|
// : node.name;
|
|
|
|
|
let safeName = node.name;
|
|
|
|
|
|
|
|
|
|
if (getContext("identifierType") === "define") {
|
|
|
|
|
return types.identifier(safeName);
|
|
|
|
@ -69,6 +80,15 @@ let trivial = {
|
|
|
|
|
return tmplIdentifierReference({ name: safeName });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
NixUnaryOperation: (_node, { defer }) => {
|
|
|
|
|
return defer((node) => {
|
|
|
|
|
if (node.operator === "-") {
|
|
|
|
|
return types.unaryExpression(node.operator, node.argument, true);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`Unsupported operator: ${node.operator}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
NixBinaryOperation: (_node, { defer }) => {
|
|
|
|
|
return defer((node) => {
|
|
|
|
|
// FIXME: Verify that all the 'operator' values match between Nix and JS!
|
|
|
|
@ -94,9 +114,9 @@ let trivial = {
|
|
|
|
|
setContext(null, "implicitContext", contextName);
|
|
|
|
|
|
|
|
|
|
return defer((node) => {
|
|
|
|
|
let setupCode = (hasParent)
|
|
|
|
|
? tmplImplicitContextNested({ environment: node.environment, parent: parentContext })
|
|
|
|
|
: tmplImplicitContextTop({ environment: node.environment });
|
|
|
|
|
let setupCode = (hasParent)
|
|
|
|
|
? tmplImplicitContextNested({ environment: node.environment, parent: parentContext })
|
|
|
|
|
: tmplImplicitContextTop({ environment: node.environment });
|
|
|
|
|
|
|
|
|
|
return tmplWithWrapper({
|
|
|
|
|
contextName: contextName,
|
|
|
|
@ -104,6 +124,16 @@ let trivial = {
|
|
|
|
|
body: node.body
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
NixConditional: (_node, { defer }) => {
|
|
|
|
|
// condition, consequence, alternative
|
|
|
|
|
return defer((node) => {
|
|
|
|
|
return tmplConditionalExpression({
|
|
|
|
|
condition: node.condition,
|
|
|
|
|
consequence: node.consequence,
|
|
|
|
|
alternative: node.alternative
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|