identifier.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _charcodes = require('./charcodes');
  2. var _whitespace = require('./whitespace');
  3. function computeIsIdentifierChar(code) {
  4. if (code < 48) return code === 36;
  5. if (code < 58) return true;
  6. if (code < 65) return false;
  7. if (code < 91) return true;
  8. if (code < 97) return code === 95;
  9. if (code < 123) return true;
  10. if (code < 128) return false;
  11. throw new Error("Should not be called with non-ASCII char code.");
  12. }
  13. const IS_IDENTIFIER_CHAR = new Uint8Array(65536); exports.IS_IDENTIFIER_CHAR = IS_IDENTIFIER_CHAR;
  14. for (let i = 0; i < 128; i++) {
  15. exports.IS_IDENTIFIER_CHAR[i] = computeIsIdentifierChar(i) ? 1 : 0;
  16. }
  17. for (let i = 128; i < 65536; i++) {
  18. exports.IS_IDENTIFIER_CHAR[i] = 1;
  19. }
  20. // Aside from whitespace and newlines, all characters outside the ASCII space are either
  21. // identifier characters or invalid. Since we're not performing code validation, we can just
  22. // treat all invalid characters as identifier characters.
  23. for (const whitespaceChar of _whitespace.WHITESPACE_CHARS) {
  24. exports.IS_IDENTIFIER_CHAR[whitespaceChar] = 0;
  25. }
  26. exports.IS_IDENTIFIER_CHAR[0x2028] = 0;
  27. exports.IS_IDENTIFIER_CHAR[0x2029] = 0;
  28. const IS_IDENTIFIER_START = exports.IS_IDENTIFIER_CHAR.slice(); exports.IS_IDENTIFIER_START = IS_IDENTIFIER_START;
  29. for (let numChar = _charcodes.charCodes.digit0; numChar <= _charcodes.charCodes.digit9; numChar++) {
  30. exports.IS_IDENTIFIER_START[numChar] = 0;
  31. }