add field exp support to objectWith
This commit is contained in:
@@ -1063,8 +1063,19 @@ class Macros {
|
|||||||
[];
|
[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var b = wholeExp.expBuilder();
|
||||||
|
|
||||||
for (exp in exps) {
|
for (exp in exps) {
|
||||||
switch (exp.def) {
|
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(_):
|
case Symbol(_):
|
||||||
objectExps.push(exp);
|
objectExps.push(exp);
|
||||||
objectExps.push(exp);
|
objectExps.push(exp);
|
||||||
|
|||||||
@@ -453,6 +453,10 @@ class BasicTestCase extends Test {
|
|||||||
_testStreamRecording();
|
_testStreamRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testObjectWith() {
|
||||||
|
_testObjectWith();
|
||||||
|
}
|
||||||
|
|
||||||
var aNullToPrint = null;
|
var aNullToPrint = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -612,6 +612,16 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
|
|||||||
(function _testDotAccessOnAlias []
|
(function _testDotAccessOnAlias []
|
||||||
(Assert.equals 5 owf.field))
|
(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 []
|
(function _testClamp []
|
||||||
(let [&mut bigValue 12
|
(let [&mut bigValue 12
|
||||||
&mut smallValue 3]
|
&mut smallValue 3]
|
||||||
|
|||||||
Reference in New Issue
Block a user