whitespace.js 848 B

123456789101112131415161718192021222324252627282930313233
  1. import {charCodes} from "./charcodes";
  2. // https://tc39.github.io/ecma262/#sec-white-space
  3. export const WHITESPACE_CHARS = [
  4. 0x0009,
  5. 0x000b,
  6. 0x000c,
  7. charCodes.space,
  8. charCodes.nonBreakingSpace,
  9. charCodes.oghamSpaceMark,
  10. 0x2000, // EN QUAD
  11. 0x2001, // EM QUAD
  12. 0x2002, // EN SPACE
  13. 0x2003, // EM SPACE
  14. 0x2004, // THREE-PER-EM SPACE
  15. 0x2005, // FOUR-PER-EM SPACE
  16. 0x2006, // SIX-PER-EM SPACE
  17. 0x2007, // FIGURE SPACE
  18. 0x2008, // PUNCTUATION SPACE
  19. 0x2009, // THIN SPACE
  20. 0x200a, // HAIR SPACE
  21. 0x202f, // NARROW NO-BREAK SPACE
  22. 0x205f, // MEDIUM MATHEMATICAL SPACE
  23. 0x3000, // IDEOGRAPHIC SPACE
  24. 0xfeff, // ZERO WIDTH NO-BREAK SPACE
  25. ];
  26. export const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  27. export const IS_WHITESPACE = new Uint8Array(65536);
  28. for (const char of WHITESPACE_CHARS) {
  29. IS_WHITESPACE[char] = 1;
  30. }