WIP
parent
bc7114036a
commit
bfe0422ff6
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
@ -1,4 +1,7 @@
|
|||||||
|
- stringify Nix
|
||||||
- convert rec attrset to use heap-of-vars
|
- convert rec attrset to use heap-of-vars
|
||||||
- wrap function args in lazy wrapper + unwrap identifier access?
|
- wrap function args in lazy wrapper + unwrap identifier access?
|
||||||
- memoize functions
|
- memoize functions
|
||||||
- let..in -> rec attrset
|
- let..in -> rec attrset
|
||||||
|
- rename 'mangling'
|
||||||
|
- verify that $ cannot appear in genuine Nix identifiers unescaped
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
{
|
rec {
|
||||||
a = 3;
|
a = "hi";
|
||||||
b = a;
|
b = a;
|
||||||
c.d = { e = 5; };
|
c.d = { e = 5; };
|
||||||
${c} = { f = 4; };
|
"${b}s" = { f = 4; };
|
||||||
|
# FIXME: The below currently breaks desugar-attrsets
|
||||||
|
# ${c}.d = { g = 6; };
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
let key = "a"; in {
|
||||||
|
a = 5;
|
||||||
|
${key} = 3;
|
||||||
|
}.a
|
@ -0,0 +1,10 @@
|
|||||||
|
let
|
||||||
|
pkgs = import <nixpkgs> { };
|
||||||
|
in
|
||||||
|
pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
pkgs.nodejs
|
||||||
|
pkgs.nodejs.python
|
||||||
|
pkgs.yarn
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const NoChange = require("../astformer/actions/no-change");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "desugar-interpolation-expressions",
|
||||||
|
visitors: {
|
||||||
|
NixAttributePath: (node) => {
|
||||||
|
if (node.attr.length === 1 && node.attr[0].type === "NixInterpolationExpression") {
|
||||||
|
// Special case: something like `{ ${foo} = "bar"; }` where the interpolation is expressed without surrounding string literal syntax
|
||||||
|
return {
|
||||||
|
... node,
|
||||||
|
// TODO: Move construction to _nixTypes
|
||||||
|
attr: [
|
||||||
|
{ type: "NixStringLiteral", parts: [
|
||||||
|
{ type: "NixInterpolationLiteral", value: "" },
|
||||||
|
node.attr[0],
|
||||||
|
{ type: "NixInterpolationLiteral", value: "" },
|
||||||
|
] },
|
||||||
|
]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return NoChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,15 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const types = require("@babel/types");
|
||||||
|
|
||||||
|
module.exports = function objectLiteral(entries) {
|
||||||
|
return types.objectExpression(
|
||||||
|
entries.map(([ key, value ]) => {
|
||||||
|
if (typeof key === "string") {
|
||||||
|
return types.objectProperty(types.stringLiteral(key), value, false);
|
||||||
|
} else {
|
||||||
|
return types.objectProperty(key, value, true);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const unpackExpression = require("./unpack-expression");
|
||||||
|
|
||||||
|
const template = require("@babel/template").default;
|
||||||
|
|
||||||
|
// Like `@babel/template`, but eliminates the wrapping ExpressionStatement
|
||||||
|
module.exports = function templateExpression(... args) {
|
||||||
|
let tmpl = template(... args);
|
||||||
|
|
||||||
|
return function (... callArgs) {
|
||||||
|
return unpackExpression(tmpl(... callArgs));
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue