当我准备为F#编写代码生成器时,我想知道是否可以通过仅生成一行值来避免进入缩进混乱.
作为这项工作的一部分,我正在考虑如何在一行中表达对象表达式,但除了在详细模式中之外无法成功.
let Expr() = (let ToString = "ToString" in { new System.Object() with member this.ToString() = ToString; member this.GetHashCode() = ToString.GetHashCode()})
Run Code Online (Sandbox Code Playgroud)
问题是我不想在详细模式下生成我的所有代码,这是兼容性功能.还有其他选择吗?
非常感谢你的见解!
弗朗索瓦
我要求这个的原因是我必须在任意表达式中生成对象表达式,我想避免计算当前行中的字符数来计算我要缩进下一行的数量.
我似乎无法获得可选参数与TypeScript中的析构参数一起使用.
为参数生成了正确的代码,但Typescript似乎不允许我在代码中使用生成的变量,从而破坏了目的.
难道我做错了什么?这是一个减少:
declare var lastDirectionWasDownish : boolean;
function goToNext(
{
root: Node = document.activeElement,
actLikeLastDirectionWasDownish:boolean = lastDirectionWasDownish
} = {}
) {
return root && actLikeLastDirectionWasDownish;
}
Run Code Online (Sandbox Code Playgroud)
汇编成
function goToNext(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.root, Node = _c === void 0 ? document.activeElement : _c, _d = _b.actLikeLastDirectionWasDownish, boolean = _d === void 0 ? lastDirectionWasDownish : _d;
return root && actLikeLastDirectionWasDownish;
}
Run Code Online (Sandbox Code Playgroud)