Support let..in

This commit is contained in:
Sven Slootweg 2022-02-02 11:52:14 +01:00
parent 5c95b808ba
commit 7f3eda388c
5 changed files with 31 additions and 0 deletions

1
samples/let-in.nix Normal file
View file

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

View file

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

View file

@ -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
};
}
};

View file

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

View file

@ -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") ]
);
}
}
};