Skip to content

Conversation

shirayu
Copy link
Contributor

@shirayu shirayu commented Jan 1, 2019

This PR can close #7.

Note: POS of a punctuation can be not "記号" but "名詞" in kuromoji.js.

src/index.js Outdated
matcherTokens.forEach((token, index) => {
const to = replaceTokenWith(token, actualTokens[index], "_capture_to_expected");
let to = "";
if (!skipped[index]) {
Copy link
Member

@azu azu Jan 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

複雑なステップを減らしたいので、できるだけ早期リターンしたい気がします。(後、不要なletを減らしたい)
skip時の動作を追うのに関数全体を見ないといけなくなってしまってるので、skip時の処理を先頭で終わらせるのがいいんじゃないかなと思いました。

// when it is skippped, do something
if(skipped[index]){
  resultText = resultText.split(token._capture).join("");
  return;
}
// when it is not skipped, do something
const to = replaceTokenWith(token, actualTokens[actualTokenIndex], "_capture_to_expected");
if (to !== null) {
  resultText = resultText.split(token._capture).join(to);
}
// Increments
++actualTokenIndex;

📝 メモ
resultText.split(token._capture).join(""); も 意味的には replaceAllIfDefined(A, B) みたいな関数なのかなー (_captureundefinedのときの動作が想像しにくそう)

@shirayu
Copy link
Contributor Author

shirayu commented Jan 2, 2019

  • 早期リターンするようにしました
  • _captureundefinedかどうかのチェックを分かりやすい場所でするようにしました

Copy link
Member

@azu azu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@azu azu merged commit 5185de5 into textlint-ja:master Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

「することが可能」の類似表現
2 participants