良い質問。
まず第一に、このコードを残した開発者は LART されるべきであることに同意します。
ただし、条件演算子の構文がorであり、可能な最長一致が winsであると考えれば、( Eclipse JSDTなどのコード フォーマッターなしで) これを理解できます。LogicalORExpression ? AssignmentExpression : AssignmentExpression… : AssignmentExpressionNoIn
同じアトミック条件演算に属する隣接する式は、文法で許可されていないため、両側を?s または:s で区切ることはできません。したがって、ECMAScript 文法に従って機能する LL(n) パーサーの立場に身を置くだけです ;-) 「このコードは、そのゴール シンボルの生成によって生成できるか?」という質問を繰り返し自問してください。答えが「いいえ」の場合は、可能な限り短い一致に戻るか、生成が機能しない場合は構文エラーで失敗します。
return (value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant);
return (value == null ? (name.local ? attrNullNS : attrNull ) : (typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant));
return ((value == null) ? (name.local ? attrNullNS : attrNull) : ( (typeof value === "function") ? (name.local ? attrFunctionNS : attrFunction) : (name.local ? attrConstantNS : attrConstant)));
など:
if (value == null)
{
if (name.local)
{
return attrNullNS;
}
else
{
return attrNull;
}
}
else
{
if (typeof value === "function")
{
if (name.local)
{
return attrFunctionNS;
}
else
{
return attrFunction;
}
}
else
{
if (name.local)
{
return attrConstantNS;
}
else
{
return attrConstant;
}
}
}
(CMIIW.) これはさらに次のように縮小できます。
if (value == null)
{
if (name.local)
{
return attrNullNS;
}
return attrNull;
}
if (typeof value === "function")
{
if (name.local)
{
return attrFunctionNS;
}
return attrFunction;
}
if (name.local)
{
return attrConstantNS;
}
return attrConstant;