Skip to main content

is_js_whitespace

Function is_js_whitespace 

Source
pub fn is_js_whitespace(c: char) -> bool
Expand description

ECMA-262 WhiteSpace (11.2) + LineTerminator (11.3): the exact character set String.prototype.trim, ToNumber(string), parseInt and parseFloat skip.

Written out rather than delegated to char::is_whitespace, which follows the Unicode White_Space property. The two sets are NOT the same and they differ in BOTH directions:

  • U+FEFF (ZWNBSP/BOM) is JS whitespace and is not Unicode White_Space, so "\u{FEFF} x".trim() kept the BOM and Number("\u{FEFF}1") was NaN.
  • U+0085 (NEL) is Unicode White_Space and is NOT JS whitespace, so "\u{85}x".trim() stripped a character node keeps.

U+180E is in neither set (Unicode 6.3 dropped it from White_Space, ES2016 dropped it from WhiteSpace), which both engines already agreed on.