Support let..in

master
Sven Slootweg 2 years ago
parent 5c95b808ba
commit 7f3eda388c

@ -0,0 +1 @@
let x = { a = 1; b = x.a + 1; c = x.b + 1; }; in x.c

@ -108,6 +108,7 @@ function convertNode(node) {
parenthesized: "NixParenthesizedExpression",
attrset: "NixAttributeSet",
rec_attrset: "NixAttributeSet",
let: "NixLetIn",
identifier: "NixIdentifier",
attr_identifier: "NixAttributeIdentifier",
attrpath: "NixAttributePath",

@ -40,5 +40,12 @@ let types = module.exports = {
type: "NixAttributeIdentifier",
name: name
};
},
NixAttributeSelection: function (expression, attributePath) {
return {
type: "NixAttributeSelection",
attrpath: types.NixAttributePath(attributePath),
expression: expression
};
}
};

@ -100,6 +100,7 @@ let trivial = {
};
module.exports = [
require("./let-in"),
require("./desugar-attrsets"),
require("./literals"),
require("./functions"),

@ -0,0 +1,21 @@
"use strict";
const nixTypes = require("./_nix-types");
module.exports = {
name: "let-in",
visitors: {
NixLetIn: (node) => {
return nixTypes.NixAttributeSelection(
nixTypes.NixAttributeSet([
... node.bind,
nixTypes.NixBinding(
[ nixTypes.NixAttributeIdentifier("$$jsNix$letBody") ],
node.body
)
], true),
[ nixTypes.NixAttributeIdentifier("$$jsNix$letBody") ]
);
}
}
};
Loading…
Cancel
Save