-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next: 省略可能引数と初期値付き引数を追加 #475
Conversation
デフォルト値の定義時に評価して使い回す方式ですかね |
とりあえずsyntax.mdに追加しました |
if (result.args[i]!.default) { | ||
result.args[i]!.default = visitNode(result.args[i]!.default!, fn) as Ast.Fn['args'][number]['default']; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この処理のiはindexではないと思います
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for-inなのでindexで間違いないと思いますが…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for-inなので対象がオブジェクトだと勘違いしてました..
配列にもfor-inって使えるんですね
一般的な用法なんでしょうか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般的かどうかはわからないです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for-ofの方が推奨されているようです
for(let value of array)
for(let index of array.keys())
for(let [index, value] of array.entries())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for...in
はプロトタイプから継承したものも列挙してしまうそうですね。
for(let index of array.keys())
を使った形に修正しました。
src/parser/syntaxes/common.ts
Outdated
let optional = false; | ||
if ((s.getKind() as TokenKind) === TokenKind.Question) { | ||
s.next(); | ||
optional = true; | ||
} | ||
let defaultExpr; | ||
if ((s.getKind() as TokenKind) === TokenKind.Eq) { | ||
s.next(); | ||
defaultExpr = parseExpr(s, false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f(arg? = defaultValue) {}
のような冗長な書き方は出来ないほうがいいかな~思いました。
?=
を一つのシンボルとして扱って、デフォルトを指定する場合でも?
を必須にするでもいいかもしれない?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あー確かに 両方つくケースのことは失念していました
?=
を一つのシンボルとして扱って、デフォルトを指定する場合でも?
を必須にするでもいいかもしれない?
これちょっと迷いますね
JavaScriptのnull合体代入を連想させる書き方ですが、実際やってることはnull合体代入に似ていますしアリではありますね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uzmoi
@f(arg? = defaultValue) {}
を禁止する方向にしました。(迷った結果Typescriptに合わせました)
条件を満たしたのでマージします。 |
一応破壊的変更なのでnextに入れます。
関数の引数定義において、各引数名に
?
を後置できるようにします。?付きの引数は省略可能となり、省略された場合nullを格納します。
また、引数に
=式
を後置することで引数の初期値を設定できるようにします。いずれでもない引数が省略された場合エラーを発生させます。