lexer.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. // Generated by CoffeeScript 1.12.6
  2. (function() {
  3. var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, HERE_JSTOKEN, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, Rewriter, SHIFT, SIMPLE_STRING_OMIT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, UNICODE_CODE_POINT_ESCAPE, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, isForFrom, isUnassignable, key, locationDataToString, ref, ref1, repeat, starts, throwSyntaxError,
  4. indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
  5. slice = [].slice;
  6. ref = require('./rewriter'), Rewriter = ref.Rewriter, INVERSES = ref.INVERSES;
  7. ref1 = require('./helpers'), count = ref1.count, starts = ref1.starts, compact = ref1.compact, repeat = ref1.repeat, invertLiterate = ref1.invertLiterate, locationDataToString = ref1.locationDataToString, throwSyntaxError = ref1.throwSyntaxError;
  8. exports.Lexer = Lexer = (function() {
  9. function Lexer() {}
  10. Lexer.prototype.tokenize = function(code, opts) {
  11. var consumed, end, i, ref2;
  12. if (opts == null) {
  13. opts = {};
  14. }
  15. this.literate = opts.literate;
  16. this.indent = 0;
  17. this.baseIndent = 0;
  18. this.indebt = 0;
  19. this.outdebt = 0;
  20. this.indents = [];
  21. this.ends = [];
  22. this.tokens = [];
  23. this.seenFor = false;
  24. this.seenImport = false;
  25. this.seenExport = false;
  26. this.importSpecifierList = false;
  27. this.exportSpecifierList = false;
  28. this.chunkLine = opts.line || 0;
  29. this.chunkColumn = opts.column || 0;
  30. code = this.clean(code);
  31. i = 0;
  32. while (this.chunk = code.slice(i)) {
  33. consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
  34. ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = ref2[0], this.chunkColumn = ref2[1];
  35. i += consumed;
  36. if (opts.untilBalanced && this.ends.length === 0) {
  37. return {
  38. tokens: this.tokens,
  39. index: i
  40. };
  41. }
  42. }
  43. this.closeIndentation();
  44. if (end = this.ends.pop()) {
  45. this.error("missing " + end.tag, end.origin[2]);
  46. }
  47. if (opts.rewrite === false) {
  48. return this.tokens;
  49. }
  50. return (new Rewriter).rewrite(this.tokens);
  51. };
  52. Lexer.prototype.clean = function(code) {
  53. if (code.charCodeAt(0) === BOM) {
  54. code = code.slice(1);
  55. }
  56. code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
  57. if (WHITESPACE.test(code)) {
  58. code = "\n" + code;
  59. this.chunkLine--;
  60. }
  61. if (this.literate) {
  62. code = invertLiterate(code);
  63. }
  64. return code;
  65. };
  66. Lexer.prototype.identifierToken = function() {
  67. var alias, colon, colonOffset, id, idLength, input, match, poppedToken, prev, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, tag, tagToken;
  68. if (!(match = IDENTIFIER.exec(this.chunk))) {
  69. return 0;
  70. }
  71. input = match[0], id = match[1], colon = match[2];
  72. idLength = id.length;
  73. poppedToken = void 0;
  74. if (id === 'own' && this.tag() === 'FOR') {
  75. this.token('OWN', id);
  76. return id.length;
  77. }
  78. if (id === 'from' && this.tag() === 'YIELD') {
  79. this.token('FROM', id);
  80. return id.length;
  81. }
  82. if (id === 'as' && this.seenImport) {
  83. if (this.value() === '*') {
  84. this.tokens[this.tokens.length - 1][0] = 'IMPORT_ALL';
  85. } else if (ref2 = this.value(), indexOf.call(COFFEE_KEYWORDS, ref2) >= 0) {
  86. this.tokens[this.tokens.length - 1][0] = 'IDENTIFIER';
  87. }
  88. if ((ref3 = this.tag()) === 'DEFAULT' || ref3 === 'IMPORT_ALL' || ref3 === 'IDENTIFIER') {
  89. this.token('AS', id);
  90. return id.length;
  91. }
  92. }
  93. if (id === 'as' && this.seenExport && ((ref4 = this.tag()) === 'IDENTIFIER' || ref4 === 'DEFAULT')) {
  94. this.token('AS', id);
  95. return id.length;
  96. }
  97. if (id === 'default' && this.seenExport && ((ref5 = this.tag()) === 'EXPORT' || ref5 === 'AS')) {
  98. this.token('DEFAULT', id);
  99. return id.length;
  100. }
  101. ref6 = this.tokens, prev = ref6[ref6.length - 1];
  102. tag = colon || (prev != null) && (((ref7 = prev[0]) === '.' || ref7 === '?.' || ref7 === '::' || ref7 === '?::') || !prev.spaced && prev[0] === '@') ? 'PROPERTY' : 'IDENTIFIER';
  103. if (tag === 'IDENTIFIER' && (indexOf.call(JS_KEYWORDS, id) >= 0 || indexOf.call(COFFEE_KEYWORDS, id) >= 0) && !(this.exportSpecifierList && indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
  104. tag = id.toUpperCase();
  105. if (tag === 'WHEN' && (ref8 = this.tag(), indexOf.call(LINE_BREAK, ref8) >= 0)) {
  106. tag = 'LEADING_WHEN';
  107. } else if (tag === 'FOR') {
  108. this.seenFor = true;
  109. } else if (tag === 'UNLESS') {
  110. tag = 'IF';
  111. } else if (tag === 'IMPORT') {
  112. this.seenImport = true;
  113. } else if (tag === 'EXPORT') {
  114. this.seenExport = true;
  115. } else if (indexOf.call(UNARY, tag) >= 0) {
  116. tag = 'UNARY';
  117. } else if (indexOf.call(RELATION, tag) >= 0) {
  118. if (tag !== 'INSTANCEOF' && this.seenFor) {
  119. tag = 'FOR' + tag;
  120. this.seenFor = false;
  121. } else {
  122. tag = 'RELATION';
  123. if (this.value() === '!') {
  124. poppedToken = this.tokens.pop();
  125. id = '!' + id;
  126. }
  127. }
  128. }
  129. } else if (tag === 'IDENTIFIER' && this.seenFor && id === 'from' && isForFrom(prev)) {
  130. tag = 'FORFROM';
  131. this.seenFor = false;
  132. }
  133. if (tag === 'IDENTIFIER' && indexOf.call(RESERVED, id) >= 0) {
  134. this.error("reserved word '" + id + "'", {
  135. length: id.length
  136. });
  137. }
  138. if (tag !== 'PROPERTY') {
  139. if (indexOf.call(COFFEE_ALIASES, id) >= 0) {
  140. alias = id;
  141. id = COFFEE_ALIAS_MAP[id];
  142. }
  143. tag = (function() {
  144. switch (id) {
  145. case '!':
  146. return 'UNARY';
  147. case '==':
  148. case '!=':
  149. return 'COMPARE';
  150. case 'true':
  151. case 'false':
  152. return 'BOOL';
  153. case 'break':
  154. case 'continue':
  155. case 'debugger':
  156. return 'STATEMENT';
  157. case '&&':
  158. case '||':
  159. return id;
  160. default:
  161. return tag;
  162. }
  163. })();
  164. }
  165. tagToken = this.token(tag, id, 0, idLength);
  166. if (alias) {
  167. tagToken.origin = [tag, alias, tagToken[2]];
  168. }
  169. if (poppedToken) {
  170. ref9 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref9[0], tagToken[2].first_column = ref9[1];
  171. }
  172. if (colon) {
  173. colonOffset = input.lastIndexOf(':');
  174. this.token(':', ':', colonOffset, colon.length);
  175. }
  176. return input.length;
  177. };
  178. Lexer.prototype.numberToken = function() {
  179. var base, lexedLength, match, number, numberValue, ref2, tag;
  180. if (!(match = NUMBER.exec(this.chunk))) {
  181. return 0;
  182. }
  183. number = match[0];
  184. lexedLength = number.length;
  185. switch (false) {
  186. case !/^0[BOX]/.test(number):
  187. this.error("radix prefix in '" + number + "' must be lowercase", {
  188. offset: 1
  189. });
  190. break;
  191. case !/^(?!0x).*E/.test(number):
  192. this.error("exponential notation in '" + number + "' must be indicated with a lowercase 'e'", {
  193. offset: number.indexOf('E')
  194. });
  195. break;
  196. case !/^0\d*[89]/.test(number):
  197. this.error("decimal literal '" + number + "' must not be prefixed with '0'", {
  198. length: lexedLength
  199. });
  200. break;
  201. case !/^0\d+/.test(number):
  202. this.error("octal literal '" + number + "' must be prefixed with '0o'", {
  203. length: lexedLength
  204. });
  205. }
  206. base = (function() {
  207. switch (number.charAt(1)) {
  208. case 'b':
  209. return 2;
  210. case 'o':
  211. return 8;
  212. case 'x':
  213. return 16;
  214. default:
  215. return null;
  216. }
  217. })();
  218. numberValue = base != null ? parseInt(number.slice(2), base) : parseFloat(number);
  219. if ((ref2 = number.charAt(1)) === 'b' || ref2 === 'o') {
  220. number = "0x" + (numberValue.toString(16));
  221. }
  222. tag = numberValue === 2e308 ? 'INFINITY' : 'NUMBER';
  223. this.token(tag, number, 0, lexedLength);
  224. return lexedLength;
  225. };
  226. Lexer.prototype.stringToken = function() {
  227. var $, attempt, delimiter, doc, end, heredoc, i, indent, indentRegex, match, quote, ref2, ref3, regex, token, tokens;
  228. quote = (STRING_START.exec(this.chunk) || [])[0];
  229. if (!quote) {
  230. return 0;
  231. }
  232. if (this.tokens.length && this.value() === 'from' && (this.seenImport || this.seenExport)) {
  233. this.tokens[this.tokens.length - 1][0] = 'FROM';
  234. }
  235. regex = (function() {
  236. switch (quote) {
  237. case "'":
  238. return STRING_SINGLE;
  239. case '"':
  240. return STRING_DOUBLE;
  241. case "'''":
  242. return HEREDOC_SINGLE;
  243. case '"""':
  244. return HEREDOC_DOUBLE;
  245. }
  246. })();
  247. heredoc = quote.length === 3;
  248. ref2 = this.matchWithInterpolations(regex, quote), tokens = ref2.tokens, end = ref2.index;
  249. $ = tokens.length - 1;
  250. delimiter = quote.charAt(0);
  251. if (heredoc) {
  252. indent = null;
  253. doc = ((function() {
  254. var j, len, results;
  255. results = [];
  256. for (i = j = 0, len = tokens.length; j < len; i = ++j) {
  257. token = tokens[i];
  258. if (token[0] === 'NEOSTRING') {
  259. results.push(token[1]);
  260. }
  261. }
  262. return results;
  263. })()).join('#{}');
  264. while (match = HEREDOC_INDENT.exec(doc)) {
  265. attempt = match[1];
  266. if (indent === null || (0 < (ref3 = attempt.length) && ref3 < indent.length)) {
  267. indent = attempt;
  268. }
  269. }
  270. if (indent) {
  271. indentRegex = RegExp("\\n" + indent, "g");
  272. }
  273. this.mergeInterpolationTokens(tokens, {
  274. delimiter: delimiter
  275. }, (function(_this) {
  276. return function(value, i) {
  277. value = _this.formatString(value, {
  278. delimiter: quote
  279. });
  280. if (indentRegex) {
  281. value = value.replace(indentRegex, '\n');
  282. }
  283. if (i === 0) {
  284. value = value.replace(LEADING_BLANK_LINE, '');
  285. }
  286. if (i === $) {
  287. value = value.replace(TRAILING_BLANK_LINE, '');
  288. }
  289. return value;
  290. };
  291. })(this));
  292. } else {
  293. this.mergeInterpolationTokens(tokens, {
  294. delimiter: delimiter
  295. }, (function(_this) {
  296. return function(value, i) {
  297. value = _this.formatString(value, {
  298. delimiter: quote
  299. });
  300. value = value.replace(SIMPLE_STRING_OMIT, function(match, offset) {
  301. if ((i === 0 && offset === 0) || (i === $ && offset + match.length === value.length)) {
  302. return '';
  303. } else {
  304. return ' ';
  305. }
  306. });
  307. return value;
  308. };
  309. })(this));
  310. }
  311. return end;
  312. };
  313. Lexer.prototype.commentToken = function() {
  314. var comment, here, match;
  315. if (!(match = this.chunk.match(COMMENT))) {
  316. return 0;
  317. }
  318. comment = match[0], here = match[1];
  319. if (here) {
  320. if (match = HERECOMMENT_ILLEGAL.exec(comment)) {
  321. this.error("block comments cannot contain " + match[0], {
  322. offset: match.index,
  323. length: match[0].length
  324. });
  325. }
  326. if (here.indexOf('\n') >= 0) {
  327. here = here.replace(RegExp("\\n" + (repeat(' ', this.indent)), "g"), '\n');
  328. }
  329. this.token('HERECOMMENT', here, 0, comment.length);
  330. }
  331. return comment.length;
  332. };
  333. Lexer.prototype.jsToken = function() {
  334. var match, script;
  335. if (!(this.chunk.charAt(0) === '`' && (match = HERE_JSTOKEN.exec(this.chunk) || JSTOKEN.exec(this.chunk)))) {
  336. return 0;
  337. }
  338. script = match[1].replace(/\\+(`|$)/g, function(string) {
  339. return string.slice(-Math.ceil(string.length / 2));
  340. });
  341. this.token('JS', script, 0, match[0].length);
  342. return match[0].length;
  343. };
  344. Lexer.prototype.regexToken = function() {
  345. var body, closed, end, flags, index, match, origin, prev, ref2, ref3, ref4, regex, tokens;
  346. switch (false) {
  347. case !(match = REGEX_ILLEGAL.exec(this.chunk)):
  348. this.error("regular expressions cannot begin with " + match[2], {
  349. offset: match.index + match[1].length
  350. });
  351. break;
  352. case !(match = this.matchWithInterpolations(HEREGEX, '///')):
  353. tokens = match.tokens, index = match.index;
  354. break;
  355. case !(match = REGEX.exec(this.chunk)):
  356. regex = match[0], body = match[1], closed = match[2];
  357. this.validateEscapes(body, {
  358. isRegex: true,
  359. offsetInChunk: 1
  360. });
  361. body = this.formatRegex(body, {
  362. delimiter: '/'
  363. });
  364. index = regex.length;
  365. ref2 = this.tokens, prev = ref2[ref2.length - 1];
  366. if (prev) {
  367. if (prev.spaced && (ref3 = prev[0], indexOf.call(CALLABLE, ref3) >= 0)) {
  368. if (!closed || POSSIBLY_DIVISION.test(regex)) {
  369. return 0;
  370. }
  371. } else if (ref4 = prev[0], indexOf.call(NOT_REGEX, ref4) >= 0) {
  372. return 0;
  373. }
  374. }
  375. if (!closed) {
  376. this.error('missing / (unclosed regex)');
  377. }
  378. break;
  379. default:
  380. return 0;
  381. }
  382. flags = REGEX_FLAGS.exec(this.chunk.slice(index))[0];
  383. end = index + flags.length;
  384. origin = this.makeToken('REGEX', null, 0, end);
  385. switch (false) {
  386. case !!VALID_FLAGS.test(flags):
  387. this.error("invalid regular expression flags " + flags, {
  388. offset: index,
  389. length: flags.length
  390. });
  391. break;
  392. case !(regex || tokens.length === 1):
  393. if (body == null) {
  394. body = this.formatHeregex(tokens[0][1]);
  395. }
  396. this.token('REGEX', "" + (this.makeDelimitedLiteral(body, {
  397. delimiter: '/'
  398. })) + flags, 0, end, origin);
  399. break;
  400. default:
  401. this.token('REGEX_START', '(', 0, 0, origin);
  402. this.token('IDENTIFIER', 'RegExp', 0, 0);
  403. this.token('CALL_START', '(', 0, 0);
  404. this.mergeInterpolationTokens(tokens, {
  405. delimiter: '"',
  406. double: true
  407. }, this.formatHeregex);
  408. if (flags) {
  409. this.token(',', ',', index - 1, 0);
  410. this.token('STRING', '"' + flags + '"', index - 1, flags.length);
  411. }
  412. this.token(')', ')', end - 1, 0);
  413. this.token('REGEX_END', ')', end - 1, 0);
  414. }
  415. return end;
  416. };
  417. Lexer.prototype.lineToken = function() {
  418. var diff, indent, match, noNewlines, size;
  419. if (!(match = MULTI_DENT.exec(this.chunk))) {
  420. return 0;
  421. }
  422. indent = match[0];
  423. this.seenFor = false;
  424. if (!this.importSpecifierList) {
  425. this.seenImport = false;
  426. }
  427. if (!this.exportSpecifierList) {
  428. this.seenExport = false;
  429. }
  430. size = indent.length - 1 - indent.lastIndexOf('\n');
  431. noNewlines = this.unfinished();
  432. if (size - this.indebt === this.indent) {
  433. if (noNewlines) {
  434. this.suppressNewlines();
  435. } else {
  436. this.newlineToken(0);
  437. }
  438. return indent.length;
  439. }
  440. if (size > this.indent) {
  441. if (noNewlines || this.tag() === 'RETURN') {
  442. this.indebt = size - this.indent;
  443. this.suppressNewlines();
  444. return indent.length;
  445. }
  446. if (!this.tokens.length) {
  447. this.baseIndent = this.indent = size;
  448. return indent.length;
  449. }
  450. diff = size - this.indent + this.outdebt;
  451. this.token('INDENT', diff, indent.length - size, size);
  452. this.indents.push(diff);
  453. this.ends.push({
  454. tag: 'OUTDENT'
  455. });
  456. this.outdebt = this.indebt = 0;
  457. this.indent = size;
  458. } else if (size < this.baseIndent) {
  459. this.error('missing indentation', {
  460. offset: indent.length
  461. });
  462. } else {
  463. this.indebt = 0;
  464. this.outdentToken(this.indent - size, noNewlines, indent.length);
  465. }
  466. return indent.length;
  467. };
  468. Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
  469. var decreasedIndent, dent, lastIndent, ref2;
  470. decreasedIndent = this.indent - moveOut;
  471. while (moveOut > 0) {
  472. lastIndent = this.indents[this.indents.length - 1];
  473. if (!lastIndent) {
  474. moveOut = 0;
  475. } else if (lastIndent === this.outdebt) {
  476. moveOut -= this.outdebt;
  477. this.outdebt = 0;
  478. } else if (lastIndent < this.outdebt) {
  479. this.outdebt -= lastIndent;
  480. moveOut -= lastIndent;
  481. } else {
  482. dent = this.indents.pop() + this.outdebt;
  483. if (outdentLength && (ref2 = this.chunk[outdentLength], indexOf.call(INDENTABLE_CLOSERS, ref2) >= 0)) {
  484. decreasedIndent -= dent - moveOut;
  485. moveOut = dent;
  486. }
  487. this.outdebt = 0;
  488. this.pair('OUTDENT');
  489. this.token('OUTDENT', moveOut, 0, outdentLength);
  490. moveOut -= dent;
  491. }
  492. }
  493. if (dent) {
  494. this.outdebt -= moveOut;
  495. }
  496. while (this.value() === ';') {
  497. this.tokens.pop();
  498. }
  499. if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
  500. this.token('TERMINATOR', '\n', outdentLength, 0);
  501. }
  502. this.indent = decreasedIndent;
  503. return this;
  504. };
  505. Lexer.prototype.whitespaceToken = function() {
  506. var match, nline, prev, ref2;
  507. if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
  508. return 0;
  509. }
  510. ref2 = this.tokens, prev = ref2[ref2.length - 1];
  511. if (prev) {
  512. prev[match ? 'spaced' : 'newLine'] = true;
  513. }
  514. if (match) {
  515. return match[0].length;
  516. } else {
  517. return 0;
  518. }
  519. };
  520. Lexer.prototype.newlineToken = function(offset) {
  521. while (this.value() === ';') {
  522. this.tokens.pop();
  523. }
  524. if (this.tag() !== 'TERMINATOR') {
  525. this.token('TERMINATOR', '\n', offset, 0);
  526. }
  527. return this;
  528. };
  529. Lexer.prototype.suppressNewlines = function() {
  530. if (this.value() === '\\') {
  531. this.tokens.pop();
  532. }
  533. return this;
  534. };
  535. Lexer.prototype.literalToken = function() {
  536. var match, message, origin, prev, ref2, ref3, ref4, ref5, ref6, skipToken, tag, token, value;
  537. if (match = OPERATOR.exec(this.chunk)) {
  538. value = match[0];
  539. if (CODE.test(value)) {
  540. this.tagParameters();
  541. }
  542. } else {
  543. value = this.chunk.charAt(0);
  544. }
  545. tag = value;
  546. ref2 = this.tokens, prev = ref2[ref2.length - 1];
  547. if (prev && indexOf.call(['='].concat(slice.call(COMPOUND_ASSIGN)), value) >= 0) {
  548. skipToken = false;
  549. if (value === '=' && ((ref3 = prev[1]) === '||' || ref3 === '&&') && !prev.spaced) {
  550. prev[0] = 'COMPOUND_ASSIGN';
  551. prev[1] += '=';
  552. prev = this.tokens[this.tokens.length - 2];
  553. skipToken = true;
  554. }
  555. if (prev && prev[0] !== 'PROPERTY') {
  556. origin = (ref4 = prev.origin) != null ? ref4 : prev;
  557. message = isUnassignable(prev[1], origin[1]);
  558. if (message) {
  559. this.error(message, origin[2]);
  560. }
  561. }
  562. if (skipToken) {
  563. return value.length;
  564. }
  565. }
  566. if (value === '{' && this.seenImport) {
  567. this.importSpecifierList = true;
  568. } else if (this.importSpecifierList && value === '}') {
  569. this.importSpecifierList = false;
  570. } else if (value === '{' && (prev != null ? prev[0] : void 0) === 'EXPORT') {
  571. this.exportSpecifierList = true;
  572. } else if (this.exportSpecifierList && value === '}') {
  573. this.exportSpecifierList = false;
  574. }
  575. if (value === ';') {
  576. this.seenFor = this.seenImport = this.seenExport = false;
  577. tag = 'TERMINATOR';
  578. } else if (value === '*' && prev[0] === 'EXPORT') {
  579. tag = 'EXPORT_ALL';
  580. } else if (indexOf.call(MATH, value) >= 0) {
  581. tag = 'MATH';
  582. } else if (indexOf.call(COMPARE, value) >= 0) {
  583. tag = 'COMPARE';
  584. } else if (indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
  585. tag = 'COMPOUND_ASSIGN';
  586. } else if (indexOf.call(UNARY, value) >= 0) {
  587. tag = 'UNARY';
  588. } else if (indexOf.call(UNARY_MATH, value) >= 0) {
  589. tag = 'UNARY_MATH';
  590. } else if (indexOf.call(SHIFT, value) >= 0) {
  591. tag = 'SHIFT';
  592. } else if (value === '?' && (prev != null ? prev.spaced : void 0)) {
  593. tag = 'BIN?';
  594. } else if (prev && !prev.spaced) {
  595. if (value === '(' && (ref5 = prev[0], indexOf.call(CALLABLE, ref5) >= 0)) {
  596. if (prev[0] === '?') {
  597. prev[0] = 'FUNC_EXIST';
  598. }
  599. tag = 'CALL_START';
  600. } else if (value === '[' && (ref6 = prev[0], indexOf.call(INDEXABLE, ref6) >= 0)) {
  601. tag = 'INDEX_START';
  602. switch (prev[0]) {
  603. case '?':
  604. prev[0] = 'INDEX_SOAK';
  605. }
  606. }
  607. }
  608. token = this.makeToken(tag, value);
  609. switch (value) {
  610. case '(':
  611. case '{':
  612. case '[':
  613. this.ends.push({
  614. tag: INVERSES[value],
  615. origin: token
  616. });
  617. break;
  618. case ')':
  619. case '}':
  620. case ']':
  621. this.pair(value);
  622. }
  623. this.tokens.push(token);
  624. return value.length;
  625. };
  626. Lexer.prototype.tagParameters = function() {
  627. var i, stack, tok, tokens;
  628. if (this.tag() !== ')') {
  629. return this;
  630. }
  631. stack = [];
  632. tokens = this.tokens;
  633. i = tokens.length;
  634. tokens[--i][0] = 'PARAM_END';
  635. while (tok = tokens[--i]) {
  636. switch (tok[0]) {
  637. case ')':
  638. stack.push(tok);
  639. break;
  640. case '(':
  641. case 'CALL_START':
  642. if (stack.length) {
  643. stack.pop();
  644. } else if (tok[0] === '(') {
  645. tok[0] = 'PARAM_START';
  646. return this;
  647. } else {
  648. return this;
  649. }
  650. }
  651. }
  652. return this;
  653. };
  654. Lexer.prototype.closeIndentation = function() {
  655. return this.outdentToken(this.indent);
  656. };
  657. Lexer.prototype.matchWithInterpolations = function(regex, delimiter) {
  658. var close, column, firstToken, index, lastToken, line, nested, offsetInChunk, open, ref2, ref3, ref4, str, strPart, tokens;
  659. tokens = [];
  660. offsetInChunk = delimiter.length;
  661. if (this.chunk.slice(0, offsetInChunk) !== delimiter) {
  662. return null;
  663. }
  664. str = this.chunk.slice(offsetInChunk);
  665. while (true) {
  666. strPart = regex.exec(str)[0];
  667. this.validateEscapes(strPart, {
  668. isRegex: delimiter.charAt(0) === '/',
  669. offsetInChunk: offsetInChunk
  670. });
  671. tokens.push(this.makeToken('NEOSTRING', strPart, offsetInChunk));
  672. str = str.slice(strPart.length);
  673. offsetInChunk += strPart.length;
  674. if (str.slice(0, 2) !== '#{') {
  675. break;
  676. }
  677. ref2 = this.getLineAndColumnFromChunk(offsetInChunk + 1), line = ref2[0], column = ref2[1];
  678. ref3 = new Lexer().tokenize(str.slice(1), {
  679. line: line,
  680. column: column,
  681. untilBalanced: true
  682. }), nested = ref3.tokens, index = ref3.index;
  683. index += 1;
  684. open = nested[0], close = nested[nested.length - 1];
  685. open[0] = open[1] = '(';
  686. close[0] = close[1] = ')';
  687. close.origin = ['', 'end of interpolation', close[2]];
  688. if (((ref4 = nested[1]) != null ? ref4[0] : void 0) === 'TERMINATOR') {
  689. nested.splice(1, 1);
  690. }
  691. tokens.push(['TOKENS', nested]);
  692. str = str.slice(index);
  693. offsetInChunk += index;
  694. }
  695. if (str.slice(0, delimiter.length) !== delimiter) {
  696. this.error("missing " + delimiter, {
  697. length: delimiter.length
  698. });
  699. }
  700. firstToken = tokens[0], lastToken = tokens[tokens.length - 1];
  701. firstToken[2].first_column -= delimiter.length;
  702. if (lastToken[1].substr(-1) === '\n') {
  703. lastToken[2].last_line += 1;
  704. lastToken[2].last_column = delimiter.length - 1;
  705. } else {
  706. lastToken[2].last_column += delimiter.length;
  707. }
  708. if (lastToken[1].length === 0) {
  709. lastToken[2].last_column -= 1;
  710. }
  711. return {
  712. tokens: tokens,
  713. index: offsetInChunk + delimiter.length
  714. };
  715. };
  716. Lexer.prototype.mergeInterpolationTokens = function(tokens, options, fn) {
  717. var converted, firstEmptyStringIndex, firstIndex, i, j, lastToken, len, locationToken, lparen, plusToken, ref2, rparen, tag, token, tokensToPush, value;
  718. if (tokens.length > 1) {
  719. lparen = this.token('STRING_START', '(', 0, 0);
  720. }
  721. firstIndex = this.tokens.length;
  722. for (i = j = 0, len = tokens.length; j < len; i = ++j) {
  723. token = tokens[i];
  724. tag = token[0], value = token[1];
  725. switch (tag) {
  726. case 'TOKENS':
  727. if (value.length === 2) {
  728. continue;
  729. }
  730. locationToken = value[0];
  731. tokensToPush = value;
  732. break;
  733. case 'NEOSTRING':
  734. converted = fn.call(this, token[1], i);
  735. if (converted.length === 0) {
  736. if (i === 0) {
  737. firstEmptyStringIndex = this.tokens.length;
  738. } else {
  739. continue;
  740. }
  741. }
  742. if (i === 2 && (firstEmptyStringIndex != null)) {
  743. this.tokens.splice(firstEmptyStringIndex, 2);
  744. }
  745. token[0] = 'STRING';
  746. token[1] = this.makeDelimitedLiteral(converted, options);
  747. locationToken = token;
  748. tokensToPush = [token];
  749. }
  750. if (this.tokens.length > firstIndex) {
  751. plusToken = this.token('+', '+');
  752. plusToken[2] = {
  753. first_line: locationToken[2].first_line,
  754. first_column: locationToken[2].first_column,
  755. last_line: locationToken[2].first_line,
  756. last_column: locationToken[2].first_column
  757. };
  758. }
  759. (ref2 = this.tokens).push.apply(ref2, tokensToPush);
  760. }
  761. if (lparen) {
  762. lastToken = tokens[tokens.length - 1];
  763. lparen.origin = [
  764. 'STRING', null, {
  765. first_line: lparen[2].first_line,
  766. first_column: lparen[2].first_column,
  767. last_line: lastToken[2].last_line,
  768. last_column: lastToken[2].last_column
  769. }
  770. ];
  771. rparen = this.token('STRING_END', ')');
  772. return rparen[2] = {
  773. first_line: lastToken[2].last_line,
  774. first_column: lastToken[2].last_column,
  775. last_line: lastToken[2].last_line,
  776. last_column: lastToken[2].last_column
  777. };
  778. }
  779. };
  780. Lexer.prototype.pair = function(tag) {
  781. var lastIndent, prev, ref2, ref3, wanted;
  782. ref2 = this.ends, prev = ref2[ref2.length - 1];
  783. if (tag !== (wanted = prev != null ? prev.tag : void 0)) {
  784. if ('OUTDENT' !== wanted) {
  785. this.error("unmatched " + tag);
  786. }
  787. ref3 = this.indents, lastIndent = ref3[ref3.length - 1];
  788. this.outdentToken(lastIndent, true);
  789. return this.pair(tag);
  790. }
  791. return this.ends.pop();
  792. };
  793. Lexer.prototype.getLineAndColumnFromChunk = function(offset) {
  794. var column, lastLine, lineCount, ref2, string;
  795. if (offset === 0) {
  796. return [this.chunkLine, this.chunkColumn];
  797. }
  798. if (offset >= this.chunk.length) {
  799. string = this.chunk;
  800. } else {
  801. string = this.chunk.slice(0, +(offset - 1) + 1 || 9e9);
  802. }
  803. lineCount = count(string, '\n');
  804. column = this.chunkColumn;
  805. if (lineCount > 0) {
  806. ref2 = string.split('\n'), lastLine = ref2[ref2.length - 1];
  807. column = lastLine.length;
  808. } else {
  809. column += string.length;
  810. }
  811. return [this.chunkLine + lineCount, column];
  812. };
  813. Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
  814. var lastCharacter, locationData, ref2, ref3, token;
  815. if (offsetInChunk == null) {
  816. offsetInChunk = 0;
  817. }
  818. if (length == null) {
  819. length = value.length;
  820. }
  821. locationData = {};
  822. ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = ref2[0], locationData.first_column = ref2[1];
  823. lastCharacter = length > 0 ? length - 1 : 0;
  824. ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = ref3[0], locationData.last_column = ref3[1];
  825. token = [tag, value, locationData];
  826. return token;
  827. };
  828. Lexer.prototype.token = function(tag, value, offsetInChunk, length, origin) {
  829. var token;
  830. token = this.makeToken(tag, value, offsetInChunk, length);
  831. if (origin) {
  832. token.origin = origin;
  833. }
  834. this.tokens.push(token);
  835. return token;
  836. };
  837. Lexer.prototype.tag = function() {
  838. var ref2, token;
  839. ref2 = this.tokens, token = ref2[ref2.length - 1];
  840. return token != null ? token[0] : void 0;
  841. };
  842. Lexer.prototype.value = function() {
  843. var ref2, token;
  844. ref2 = this.tokens, token = ref2[ref2.length - 1];
  845. return token != null ? token[1] : void 0;
  846. };
  847. Lexer.prototype.unfinished = function() {
  848. var ref2;
  849. return LINE_CONTINUER.test(this.chunk) || ((ref2 = this.tag()) === '\\' || ref2 === '.' || ref2 === '?.' || ref2 === '?::' || ref2 === 'UNARY' || ref2 === 'MATH' || ref2 === 'UNARY_MATH' || ref2 === '+' || ref2 === '-' || ref2 === '**' || ref2 === 'SHIFT' || ref2 === 'RELATION' || ref2 === 'COMPARE' || ref2 === '&' || ref2 === '^' || ref2 === '|' || ref2 === '&&' || ref2 === '||' || ref2 === 'BIN?' || ref2 === 'THROW' || ref2 === 'EXTENDS' || ref2 === 'DEFAULT');
  850. };
  851. Lexer.prototype.formatString = function(str, options) {
  852. return this.replaceUnicodeCodePointEscapes(str.replace(STRING_OMIT, '$1'), options);
  853. };
  854. Lexer.prototype.formatHeregex = function(str) {
  855. return this.formatRegex(str.replace(HEREGEX_OMIT, '$1$2'), {
  856. delimiter: '///'
  857. });
  858. };
  859. Lexer.prototype.formatRegex = function(str, options) {
  860. return this.replaceUnicodeCodePointEscapes(str, options);
  861. };
  862. Lexer.prototype.unicodeCodePointToUnicodeEscapes = function(codePoint) {
  863. var high, low, toUnicodeEscape;
  864. toUnicodeEscape = function(val) {
  865. var str;
  866. str = val.toString(16);
  867. return "\\u" + (repeat('0', 4 - str.length)) + str;
  868. };
  869. if (codePoint < 0x10000) {
  870. return toUnicodeEscape(codePoint);
  871. }
  872. high = Math.floor((codePoint - 0x10000) / 0x400) + 0xD800;
  873. low = (codePoint - 0x10000) % 0x400 + 0xDC00;
  874. return "" + (toUnicodeEscape(high)) + (toUnicodeEscape(low));
  875. };
  876. Lexer.prototype.replaceUnicodeCodePointEscapes = function(str, options) {
  877. return str.replace(UNICODE_CODE_POINT_ESCAPE, (function(_this) {
  878. return function(match, escapedBackslash, codePointHex, offset) {
  879. var codePointDecimal;
  880. if (escapedBackslash) {
  881. return escapedBackslash;
  882. }
  883. codePointDecimal = parseInt(codePointHex, 16);
  884. if (codePointDecimal > 0x10ffff) {
  885. _this.error("unicode code point escapes greater than \\u{10ffff} are not allowed", {
  886. offset: offset + options.delimiter.length,
  887. length: codePointHex.length + 4
  888. });
  889. }
  890. return _this.unicodeCodePointToUnicodeEscapes(codePointDecimal);
  891. };
  892. })(this));
  893. };
  894. Lexer.prototype.validateEscapes = function(str, options) {
  895. var before, hex, invalidEscape, invalidEscapeRegex, match, message, octal, ref2, unicode, unicodeCodePoint;
  896. if (options == null) {
  897. options = {};
  898. }
  899. invalidEscapeRegex = options.isRegex ? REGEX_INVALID_ESCAPE : STRING_INVALID_ESCAPE;
  900. match = invalidEscapeRegex.exec(str);
  901. if (!match) {
  902. return;
  903. }
  904. match[0], before = match[1], octal = match[2], hex = match[3], unicodeCodePoint = match[4], unicode = match[5];
  905. message = octal ? "octal escape sequences are not allowed" : "invalid escape sequence";
  906. invalidEscape = "\\" + (octal || hex || unicodeCodePoint || unicode);
  907. return this.error(message + " " + invalidEscape, {
  908. offset: ((ref2 = options.offsetInChunk) != null ? ref2 : 0) + match.index + before.length,
  909. length: invalidEscape.length
  910. });
  911. };
  912. Lexer.prototype.makeDelimitedLiteral = function(body, options) {
  913. var regex;
  914. if (options == null) {
  915. options = {};
  916. }
  917. if (body === '' && options.delimiter === '/') {
  918. body = '(?:)';
  919. }
  920. regex = RegExp("(\\\\\\\\)|(\\\\0(?=[1-7]))|\\\\?(" + options.delimiter + ")|\\\\?(?:(\\n)|(\\r)|(\\u2028)|(\\u2029))|(\\\\.)", "g");
  921. body = body.replace(regex, function(match, backslash, nul, delimiter, lf, cr, ls, ps, other) {
  922. switch (false) {
  923. case !backslash:
  924. if (options.double) {
  925. return backslash + backslash;
  926. } else {
  927. return backslash;
  928. }
  929. case !nul:
  930. return '\\x00';
  931. case !delimiter:
  932. return "\\" + delimiter;
  933. case !lf:
  934. return '\\n';
  935. case !cr:
  936. return '\\r';
  937. case !ls:
  938. return '\\u2028';
  939. case !ps:
  940. return '\\u2029';
  941. case !other:
  942. if (options.double) {
  943. return "\\" + other;
  944. } else {
  945. return other;
  946. }
  947. }
  948. });
  949. return "" + options.delimiter + body + options.delimiter;
  950. };
  951. Lexer.prototype.error = function(message, options) {
  952. var first_column, first_line, location, ref2, ref3, ref4;
  953. if (options == null) {
  954. options = {};
  955. }
  956. location = 'first_line' in options ? options : ((ref3 = this.getLineAndColumnFromChunk((ref2 = options.offset) != null ? ref2 : 0), first_line = ref3[0], first_column = ref3[1], ref3), {
  957. first_line: first_line,
  958. first_column: first_column,
  959. last_column: first_column + ((ref4 = options.length) != null ? ref4 : 1) - 1
  960. });
  961. return throwSyntaxError(message, location);
  962. };
  963. return Lexer;
  964. })();
  965. isUnassignable = function(name, displayName) {
  966. if (displayName == null) {
  967. displayName = name;
  968. }
  969. switch (false) {
  970. case indexOf.call(slice.call(JS_KEYWORDS).concat(slice.call(COFFEE_KEYWORDS)), name) < 0:
  971. return "keyword '" + displayName + "' can't be assigned";
  972. case indexOf.call(STRICT_PROSCRIBED, name) < 0:
  973. return "'" + displayName + "' can't be assigned";
  974. case indexOf.call(RESERVED, name) < 0:
  975. return "reserved word '" + displayName + "' can't be assigned";
  976. default:
  977. return false;
  978. }
  979. };
  980. exports.isUnassignable = isUnassignable;
  981. isForFrom = function(prev) {
  982. var ref2;
  983. if (prev[0] === 'IDENTIFIER') {
  984. if (prev[1] === 'from') {
  985. prev[1][0] = 'IDENTIFIER';
  986. true;
  987. }
  988. return true;
  989. } else if (prev[0] === 'FOR') {
  990. return false;
  991. } else if ((ref2 = prev[1]) === '{' || ref2 === '[' || ref2 === ',' || ref2 === ':') {
  992. return false;
  993. } else {
  994. return true;
  995. }
  996. };
  997. JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'yield', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super', 'import', 'export', 'default'];
  998. COFFEE_KEYWORDS = ['undefined', 'Infinity', 'NaN', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
  999. COFFEE_ALIAS_MAP = {
  1000. and: '&&',
  1001. or: '||',
  1002. is: '==',
  1003. isnt: '!=',
  1004. not: '!',
  1005. yes: 'true',
  1006. no: 'false',
  1007. on: 'true',
  1008. off: 'false'
  1009. };
  1010. COFFEE_ALIASES = (function() {
  1011. var results;
  1012. results = [];
  1013. for (key in COFFEE_ALIAS_MAP) {
  1014. results.push(key);
  1015. }
  1016. return results;
  1017. })();
  1018. COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
  1019. RESERVED = ['case', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'native', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'static'];
  1020. STRICT_PROSCRIBED = ['arguments', 'eval'];
  1021. exports.JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);
  1022. BOM = 65279;
  1023. IDENTIFIER = /^(?!\d)((?:(?!\s)[$\w\x7f-\uffff])+)([^\n\S]*:(?!:))?/;
  1024. NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
  1025. OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>*\/%])\2=?|\?(\.|::)|\.{2,3})/;
  1026. WHITESPACE = /^[^\n\S]+/;
  1027. COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|###$)|^(?:\s*#(?!##[^#]).*)+/;
  1028. CODE = /^[-=]>/;
  1029. MULTI_DENT = /^(?:\n[^\n\S]*)+/;
  1030. JSTOKEN = /^`(?!``)((?:[^`\\]|\\[\s\S])*)`/;
  1031. HERE_JSTOKEN = /^```((?:[^`\\]|\\[\s\S]|`(?!``))*)```/;
  1032. STRING_START = /^(?:'''|"""|'|")/;
  1033. STRING_SINGLE = /^(?:[^\\']|\\[\s\S])*/;
  1034. STRING_DOUBLE = /^(?:[^\\"#]|\\[\s\S]|\#(?!\{))*/;
  1035. HEREDOC_SINGLE = /^(?:[^\\']|\\[\s\S]|'(?!''))*/;
  1036. HEREDOC_DOUBLE = /^(?:[^\\"#]|\\[\s\S]|"(?!"")|\#(?!\{))*/;
  1037. STRING_OMIT = /((?:\\\\)+)|\\[^\S\n]*\n\s*/g;
  1038. SIMPLE_STRING_OMIT = /\s*\n\s*/g;
  1039. HEREDOC_INDENT = /\n+([^\n\S]*)(?=\S)/g;
  1040. REGEX = /^\/(?!\/)((?:[^[\/\n\\]|\\[^\n]|\[(?:\\[^\n]|[^\]\n\\])*\])*)(\/)?/;
  1041. REGEX_FLAGS = /^\w*/;
  1042. VALID_FLAGS = /^(?!.*(.).*\1)[imguy]*$/;
  1043. HEREGEX = /^(?:[^\\\/#]|\\[\s\S]|\/(?!\/\/)|\#(?!\{))*/;
  1044. HEREGEX_OMIT = /((?:\\\\)+)|\\(\s)|\s+(?:#.*)?/g;
  1045. REGEX_ILLEGAL = /^(\/|\/{3}\s*)(\*)/;
  1046. POSSIBLY_DIVISION = /^\/=?\s/;
  1047. HERECOMMENT_ILLEGAL = /\*\//;
  1048. LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/;
  1049. STRING_INVALID_ESCAPE = /((?:^|[^\\])(?:\\\\)*)\\(?:(0[0-7]|[1-7])|(x(?![\da-fA-F]{2}).{0,2})|(u\{(?![\da-fA-F]{1,}\})[^}]*\}?)|(u(?!\{|[\da-fA-F]{4}).{0,4}))/;
  1050. REGEX_INVALID_ESCAPE = /((?:^|[^\\])(?:\\\\)*)\\(?:(0[0-7])|(x(?![\da-fA-F]{2}).{0,2})|(u\{(?![\da-fA-F]{1,}\})[^}]*\}?)|(u(?!\{|[\da-fA-F]{4}).{0,4}))/;
  1051. UNICODE_CODE_POINT_ESCAPE = /(\\\\)|\\u\{([\da-fA-F]+)\}/g;
  1052. LEADING_BLANK_LINE = /^[^\n\S]*\n/;
  1053. TRAILING_BLANK_LINE = /\n[^\n\S]*$/;
  1054. TRAILING_SPACES = /\s+$/;
  1055. COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=', '**=', '//=', '%%='];
  1056. UNARY = ['NEW', 'TYPEOF', 'DELETE', 'DO'];
  1057. UNARY_MATH = ['!', '~'];
  1058. SHIFT = ['<<', '>>', '>>>'];
  1059. COMPARE = ['==', '!=', '<', '>', '<=', '>='];
  1060. MATH = ['*', '/', '%', '//', '%%'];
  1061. RELATION = ['IN', 'OF', 'INSTANCEOF'];
  1062. BOOL = ['TRUE', 'FALSE'];
  1063. CALLABLE = ['IDENTIFIER', 'PROPERTY', ')', ']', '?', '@', 'THIS', 'SUPER'];
  1064. INDEXABLE = CALLABLE.concat(['NUMBER', 'INFINITY', 'NAN', 'STRING', 'STRING_END', 'REGEX', 'REGEX_END', 'BOOL', 'NULL', 'UNDEFINED', '}', '::']);
  1065. NOT_REGEX = INDEXABLE.concat(['++', '--']);
  1066. LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
  1067. INDENTABLE_CLOSERS = [')', '}', ']'];
  1068. }).call(this);