add field exp support to objectWith

This commit is contained in:
2024-03-08 11:27:09 +01:00
parent d051f19c65
commit a949fa24f7
3 changed files with 25 additions and 0 deletions

View File

@@ -1063,8 +1063,19 @@ class Macros {
[];
}
var b = wholeExp.expBuilder();
for (exp in exps) {
switch (exp.def) {
// (objectWith obj.field) expands to (object field obj.field)
case Symbol(withDots) if (withDots.indexOf(".") != -1):
var fieldName = withDots.split(".").pop();
objectExps.push(b.symbol(fieldName));
objectExps.push(exp);
// (objectWith .field <exp>) expands to (object field .field <exp>)
case FieldExp(fieldName, innerExp, _):
objectExps.push(b.symbol(fieldName));
objectExps.push(exp);
case Symbol(_):
objectExps.push(exp);
objectExps.push(exp);

View File

@@ -453,6 +453,10 @@ class BasicTestCase extends Test {
_testStreamRecording();
}
function testObjectWith() {
_testObjectWith();
}
var aNullToPrint = null;
}

View File

@@ -612,6 +612,16 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(function _testDotAccessOnAlias []
(Assert.equals 5 owf.field))
(function _testObjectWith []
(let [obj (object name "obby" purpose "idk" id 5)
nil null
id 7
objWith (objectWith obj.name .purpose obj id nil?.notAField)]
(Assert.equals "obby" objWith.name)
(Assert.equals "idk" objWith.purpose)
(Assert.equals 7 objWith.id)
(Assert.equals null objWith.notAField)))
(function _testClamp []
(let [&mut bigValue 12
&mut smallValue 3]