tc39 / proposal-intl-segmenter

Unicode text segmentation for ECMAScript
https://tc39.github.io/proposal-intl-segmenter/
146 stars 16 forks source link

Why do we need to create a isWordLike: undefined in CreateSegmentDataObject If granularity is NOT "word" #127

Closed FrankYFTang closed 4 years ago

FrankYFTang commented 4 years ago

In https://tc39.es/proposal-intl-segmenter/#sec-createsegmentdataobject

CreateSegmentDataObject ( segmenter, string, startIndex, endIndex )
11. If granularity is "word", then
  a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]].
12. Else
  a. Let isWordLike be undefined.
13. Perform ! CreateDataPropertyOrThrow(result, "isWordLike", isWordLike).
14. Return result.

But why do we need to create an isWordLike w/ the value undefined when the granularity is NOT "word"? Why don't we just not create it instead?

I suggest we change it to

CreateSegmentDataObject ( segmenter, string, startIndex, endIndex )
11. If granularity is "word", then
  a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]].
  b. Perform ! CreateDataPropertyOrThrow(result, "isWordLike", isWordLike).
12. Return result.

@tc39/ecma-fellows @littledan @gibson042 @zbraniecki @mathiasbynens

gibson042 commented 4 years ago

Works for me. Would you like to submit the PR?

FrankYFTang commented 4 years ago

sure. see https://github.com/tc39/proposal-intl-segmenter/pull/128