walkCssTokens.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /**
  7. * @typedef {Object} CssTokenCallbacks
  8. * @property {function(string, number): boolean} isSelector
  9. * @property {function(string, number, number, number, number): number=} url
  10. * @property {function(string, number, number): number=} string
  11. * @property {function(string, number, number): number=} leftParenthesis
  12. * @property {function(string, number, number): number=} rightParenthesis
  13. * @property {function(string, number, number): number=} pseudoFunction
  14. * @property {function(string, number, number): number=} function
  15. * @property {function(string, number, number): number=} pseudoClass
  16. * @property {function(string, number, number): number=} atKeyword
  17. * @property {function(string, number, number): number=} class
  18. * @property {function(string, number, number): number=} identifier
  19. * @property {function(string, number, number): number=} id
  20. * @property {function(string, number, number): number=} leftCurlyBracket
  21. * @property {function(string, number, number): number=} rightCurlyBracket
  22. * @property {function(string, number, number): number=} semicolon
  23. * @property {function(string, number, number): number=} comma
  24. */
  25. /** @typedef {function(string, number, CssTokenCallbacks): number} CharHandler */
  26. // spec: https://drafts.csswg.org/css-syntax/
  27. const CC_LINE_FEED = "\n".charCodeAt(0);
  28. const CC_CARRIAGE_RETURN = "\r".charCodeAt(0);
  29. const CC_FORM_FEED = "\f".charCodeAt(0);
  30. const CC_TAB = "\t".charCodeAt(0);
  31. const CC_SPACE = " ".charCodeAt(0);
  32. const CC_SLASH = "/".charCodeAt(0);
  33. const CC_BACK_SLASH = "\\".charCodeAt(0);
  34. const CC_ASTERISK = "*".charCodeAt(0);
  35. const CC_LEFT_PARENTHESIS = "(".charCodeAt(0);
  36. const CC_RIGHT_PARENTHESIS = ")".charCodeAt(0);
  37. const CC_LEFT_CURLY = "{".charCodeAt(0);
  38. const CC_RIGHT_CURLY = "}".charCodeAt(0);
  39. const CC_QUOTATION_MARK = '"'.charCodeAt(0);
  40. const CC_APOSTROPHE = "'".charCodeAt(0);
  41. const CC_FULL_STOP = ".".charCodeAt(0);
  42. const CC_COLON = ":".charCodeAt(0);
  43. const CC_SEMICOLON = ";".charCodeAt(0);
  44. const CC_COMMA = ",".charCodeAt(0);
  45. const CC_PERCENTAGE = "%".charCodeAt(0);
  46. const CC_AT_SIGN = "@".charCodeAt(0);
  47. const CC_LOW_LINE = "_".charCodeAt(0);
  48. const CC_LOWER_A = "a".charCodeAt(0);
  49. const CC_LOWER_U = "u".charCodeAt(0);
  50. const CC_LOWER_E = "e".charCodeAt(0);
  51. const CC_LOWER_Z = "z".charCodeAt(0);
  52. const CC_UPPER_A = "A".charCodeAt(0);
  53. const CC_UPPER_E = "E".charCodeAt(0);
  54. const CC_UPPER_Z = "Z".charCodeAt(0);
  55. const CC_0 = "0".charCodeAt(0);
  56. const CC_9 = "9".charCodeAt(0);
  57. const CC_NUMBER_SIGN = "#".charCodeAt(0);
  58. const CC_PLUS_SIGN = "+".charCodeAt(0);
  59. const CC_HYPHEN_MINUS = "-".charCodeAt(0);
  60. const CC_LESS_THAN_SIGN = "<".charCodeAt(0);
  61. const CC_GREATER_THAN_SIGN = ">".charCodeAt(0);
  62. const _isNewLine = cc => {
  63. return (
  64. cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED
  65. );
  66. };
  67. /** @type {CharHandler} */
  68. const consumeSpace = (input, pos, callbacks) => {
  69. let cc;
  70. do {
  71. pos++;
  72. cc = input.charCodeAt(pos);
  73. } while (_isWhiteSpace(cc));
  74. return pos;
  75. };
  76. const _isWhiteSpace = cc => {
  77. return (
  78. cc === CC_LINE_FEED ||
  79. cc === CC_CARRIAGE_RETURN ||
  80. cc === CC_FORM_FEED ||
  81. cc === CC_TAB ||
  82. cc === CC_SPACE
  83. );
  84. };
  85. /** @type {CharHandler} */
  86. const consumeSingleCharToken = (input, pos, callbacks) => {
  87. return pos + 1;
  88. };
  89. /** @type {CharHandler} */
  90. const consumePotentialComment = (input, pos, callbacks) => {
  91. pos++;
  92. if (pos === input.length) return pos;
  93. let cc = input.charCodeAt(pos);
  94. if (cc !== CC_ASTERISK) return pos;
  95. for (;;) {
  96. pos++;
  97. if (pos === input.length) return pos;
  98. cc = input.charCodeAt(pos);
  99. while (cc === CC_ASTERISK) {
  100. pos++;
  101. if (pos === input.length) return pos;
  102. cc = input.charCodeAt(pos);
  103. if (cc === CC_SLASH) return pos + 1;
  104. }
  105. }
  106. };
  107. /** @type {function(number): CharHandler} */
  108. const consumeString = end => (input, pos, callbacks) => {
  109. const start = pos;
  110. pos = _consumeString(input, pos, end);
  111. if (callbacks.string !== undefined) {
  112. pos = callbacks.string(input, start, pos);
  113. }
  114. return pos;
  115. };
  116. const _consumeString = (input, pos, end) => {
  117. pos++;
  118. for (;;) {
  119. if (pos === input.length) return pos;
  120. const cc = input.charCodeAt(pos);
  121. if (cc === end) return pos + 1;
  122. if (_isNewLine(cc)) {
  123. // bad string
  124. return pos;
  125. }
  126. if (cc === CC_BACK_SLASH) {
  127. // we don't need to fully parse the escaped code point
  128. // just skip over a potential new line
  129. pos++;
  130. if (pos === input.length) return pos;
  131. pos++;
  132. } else {
  133. pos++;
  134. }
  135. }
  136. };
  137. const _isIdentifierStartCode = cc => {
  138. return (
  139. cc === CC_LOW_LINE ||
  140. (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
  141. (cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
  142. cc > 0x80
  143. );
  144. };
  145. const _isDigit = cc => {
  146. return cc >= CC_0 && cc <= CC_9;
  147. };
  148. const _startsIdentifier = (input, pos) => {
  149. const cc = input.charCodeAt(pos);
  150. if (cc === CC_HYPHEN_MINUS) {
  151. if (pos === input.length) return false;
  152. const cc = input.charCodeAt(pos + 1);
  153. if (cc === CC_HYPHEN_MINUS) return true;
  154. if (cc === CC_BACK_SLASH) {
  155. const cc = input.charCodeAt(pos + 2);
  156. return !_isNewLine(cc);
  157. }
  158. return _isIdentifierStartCode(cc);
  159. }
  160. if (cc === CC_BACK_SLASH) {
  161. const cc = input.charCodeAt(pos + 1);
  162. return !_isNewLine(cc);
  163. }
  164. return _isIdentifierStartCode(cc);
  165. };
  166. /** @type {CharHandler} */
  167. const consumeNumberSign = (input, pos, callbacks) => {
  168. const start = pos;
  169. pos++;
  170. if (pos === input.length) return pos;
  171. if (callbacks.isSelector(input, pos) && _startsIdentifier(input, pos)) {
  172. pos = _consumeIdentifier(input, pos);
  173. if (callbacks.id !== undefined) {
  174. return callbacks.id(input, start, pos);
  175. }
  176. }
  177. return pos;
  178. };
  179. /** @type {CharHandler} */
  180. const consumeMinus = (input, pos, callbacks) => {
  181. const start = pos;
  182. pos++;
  183. if (pos === input.length) return pos;
  184. const cc = input.charCodeAt(pos);
  185. if (cc === CC_FULL_STOP || _isDigit(cc)) {
  186. return consumeNumericToken(input, pos, callbacks);
  187. } else if (cc === CC_HYPHEN_MINUS) {
  188. pos++;
  189. if (pos === input.length) return pos;
  190. const cc = input.charCodeAt(pos);
  191. if (cc === CC_GREATER_THAN_SIGN) {
  192. return pos + 1;
  193. } else {
  194. pos = _consumeIdentifier(input, pos);
  195. if (callbacks.identifier !== undefined) {
  196. return callbacks.identifier(input, start, pos);
  197. }
  198. }
  199. } else if (cc === CC_BACK_SLASH) {
  200. if (pos + 1 === input.length) return pos;
  201. const cc = input.charCodeAt(pos + 1);
  202. if (_isNewLine(cc)) return pos;
  203. pos = _consumeIdentifier(input, pos);
  204. if (callbacks.identifier !== undefined) {
  205. return callbacks.identifier(input, start, pos);
  206. }
  207. } else if (_isIdentifierStartCode(cc)) {
  208. pos++;
  209. pos = _consumeIdentifier(input, pos);
  210. if (callbacks.identifier !== undefined) {
  211. return callbacks.identifier(input, start, pos);
  212. }
  213. }
  214. return pos;
  215. };
  216. /** @type {CharHandler} */
  217. const consumeDot = (input, pos, callbacks) => {
  218. const start = pos;
  219. pos++;
  220. if (pos === input.length) return pos;
  221. const cc = input.charCodeAt(pos);
  222. if (_isDigit(cc)) return consumeNumericToken(input, pos - 2, callbacks);
  223. if (!callbacks.isSelector(input, pos) || !_startsIdentifier(input, pos))
  224. return pos;
  225. pos = _consumeIdentifier(input, pos);
  226. if (callbacks.class !== undefined) return callbacks.class(input, start, pos);
  227. return pos;
  228. };
  229. /** @type {CharHandler} */
  230. const consumeNumericToken = (input, pos, callbacks) => {
  231. pos = _consumeNumber(input, pos);
  232. if (pos === input.length) return pos;
  233. if (_startsIdentifier(input, pos)) return _consumeIdentifier(input, pos);
  234. const cc = input.charCodeAt(pos);
  235. if (cc === CC_PERCENTAGE) return pos + 1;
  236. return pos;
  237. };
  238. /** @type {CharHandler} */
  239. const consumeOtherIdentifier = (input, pos, callbacks) => {
  240. const start = pos;
  241. pos = _consumeIdentifier(input, pos);
  242. if (
  243. pos !== input.length &&
  244. !callbacks.isSelector(input, pos) &&
  245. input.charCodeAt(pos) === CC_LEFT_PARENTHESIS
  246. ) {
  247. pos++;
  248. if (callbacks.function !== undefined) {
  249. return callbacks.function(input, start, pos);
  250. }
  251. } else {
  252. if (callbacks.identifier !== undefined) {
  253. return callbacks.identifier(input, start, pos);
  254. }
  255. }
  256. return pos;
  257. };
  258. /** @type {CharHandler} */
  259. const consumePotentialUrl = (input, pos, callbacks) => {
  260. const start = pos;
  261. pos = _consumeIdentifier(input, pos);
  262. if (pos === start + 3 && input.slice(start, pos + 1) === "url(") {
  263. pos++;
  264. let cc = input.charCodeAt(pos);
  265. while (_isWhiteSpace(cc)) {
  266. pos++;
  267. if (pos === input.length) return pos;
  268. cc = input.charCodeAt(pos);
  269. }
  270. if (cc === CC_QUOTATION_MARK || cc === CC_APOSTROPHE) {
  271. pos++;
  272. const contentStart = pos;
  273. pos = _consumeString(input, pos, cc);
  274. const contentEnd = pos - 1;
  275. cc = input.charCodeAt(pos);
  276. while (_isWhiteSpace(cc)) {
  277. pos++;
  278. if (pos === input.length) return pos;
  279. cc = input.charCodeAt(pos);
  280. }
  281. if (cc !== CC_RIGHT_PARENTHESIS) return pos;
  282. pos++;
  283. if (callbacks.url !== undefined)
  284. return callbacks.url(input, start, pos, contentStart, contentEnd);
  285. return pos;
  286. } else {
  287. const contentStart = pos;
  288. let contentEnd;
  289. for (;;) {
  290. if (cc === CC_BACK_SLASH) {
  291. pos++;
  292. if (pos === input.length) return pos;
  293. pos++;
  294. } else if (_isWhiteSpace(cc)) {
  295. contentEnd = pos;
  296. do {
  297. pos++;
  298. if (pos === input.length) return pos;
  299. cc = input.charCodeAt(pos);
  300. } while (_isWhiteSpace(cc));
  301. if (cc !== CC_RIGHT_PARENTHESIS) return pos;
  302. pos++;
  303. if (callbacks.url !== undefined) {
  304. return callbacks.url(input, start, pos, contentStart, contentEnd);
  305. }
  306. return pos;
  307. } else if (cc === CC_RIGHT_PARENTHESIS) {
  308. contentEnd = pos;
  309. pos++;
  310. if (callbacks.url !== undefined) {
  311. return callbacks.url(input, start, pos, contentStart, contentEnd);
  312. }
  313. return pos;
  314. } else if (cc === CC_LEFT_PARENTHESIS) {
  315. return pos;
  316. } else {
  317. pos++;
  318. }
  319. if (pos === input.length) return pos;
  320. cc = input.charCodeAt(pos);
  321. }
  322. }
  323. } else {
  324. if (callbacks.identifier !== undefined) {
  325. return callbacks.identifier(input, start, pos);
  326. }
  327. return pos;
  328. }
  329. };
  330. /** @type {CharHandler} */
  331. const consumePotentialPseudo = (input, pos, callbacks) => {
  332. const start = pos;
  333. pos++;
  334. if (!callbacks.isSelector(input, pos) || !_startsIdentifier(input, pos))
  335. return pos;
  336. pos = _consumeIdentifier(input, pos);
  337. let cc = input.charCodeAt(pos);
  338. if (cc === CC_LEFT_PARENTHESIS) {
  339. pos++;
  340. if (callbacks.pseudoFunction !== undefined) {
  341. return callbacks.pseudoFunction(input, start, pos);
  342. }
  343. return pos;
  344. }
  345. if (callbacks.pseudoClass !== undefined) {
  346. return callbacks.pseudoClass(input, start, pos);
  347. }
  348. return pos;
  349. };
  350. /** @type {CharHandler} */
  351. const consumeLeftParenthesis = (input, pos, callbacks) => {
  352. pos++;
  353. if (callbacks.leftParenthesis !== undefined) {
  354. return callbacks.leftParenthesis(input, pos - 1, pos);
  355. }
  356. return pos;
  357. };
  358. /** @type {CharHandler} */
  359. const consumeRightParenthesis = (input, pos, callbacks) => {
  360. pos++;
  361. if (callbacks.rightParenthesis !== undefined) {
  362. return callbacks.rightParenthesis(input, pos - 1, pos);
  363. }
  364. return pos;
  365. };
  366. /** @type {CharHandler} */
  367. const consumeLeftCurlyBracket = (input, pos, callbacks) => {
  368. pos++;
  369. if (callbacks.leftCurlyBracket !== undefined) {
  370. return callbacks.leftCurlyBracket(input, pos - 1, pos);
  371. }
  372. return pos;
  373. };
  374. /** @type {CharHandler} */
  375. const consumeRightCurlyBracket = (input, pos, callbacks) => {
  376. pos++;
  377. if (callbacks.rightCurlyBracket !== undefined) {
  378. return callbacks.rightCurlyBracket(input, pos - 1, pos);
  379. }
  380. return pos;
  381. };
  382. /** @type {CharHandler} */
  383. const consumeSemicolon = (input, pos, callbacks) => {
  384. pos++;
  385. if (callbacks.semicolon !== undefined) {
  386. return callbacks.semicolon(input, pos - 1, pos);
  387. }
  388. return pos;
  389. };
  390. /** @type {CharHandler} */
  391. const consumeComma = (input, pos, callbacks) => {
  392. pos++;
  393. if (callbacks.comma !== undefined) {
  394. return callbacks.comma(input, pos - 1, pos);
  395. }
  396. return pos;
  397. };
  398. const _consumeIdentifier = (input, pos) => {
  399. for (;;) {
  400. const cc = input.charCodeAt(pos);
  401. if (cc === CC_BACK_SLASH) {
  402. pos++;
  403. if (pos === input.length) return pos;
  404. pos++;
  405. } else if (
  406. _isIdentifierStartCode(cc) ||
  407. _isDigit(cc) ||
  408. cc === CC_HYPHEN_MINUS
  409. ) {
  410. pos++;
  411. } else {
  412. return pos;
  413. }
  414. }
  415. };
  416. const _consumeNumber = (input, pos) => {
  417. pos++;
  418. if (pos === input.length) return pos;
  419. let cc = input.charCodeAt(pos);
  420. while (_isDigit(cc)) {
  421. pos++;
  422. if (pos === input.length) return pos;
  423. cc = input.charCodeAt(pos);
  424. }
  425. if (cc === CC_FULL_STOP && pos + 1 !== input.length) {
  426. const next = input.charCodeAt(pos + 1);
  427. if (_isDigit(next)) {
  428. pos += 2;
  429. cc = input.charCodeAt(pos);
  430. while (_isDigit(cc)) {
  431. pos++;
  432. if (pos === input.length) return pos;
  433. cc = input.charCodeAt(pos);
  434. }
  435. }
  436. }
  437. if (cc === CC_LOWER_E || cc === CC_UPPER_E) {
  438. if (pos + 1 !== input.length) {
  439. const next = input.charCodeAt(pos + 2);
  440. if (_isDigit(next)) {
  441. pos += 2;
  442. } else if (
  443. (next === CC_HYPHEN_MINUS || next === CC_PLUS_SIGN) &&
  444. pos + 2 !== input.length
  445. ) {
  446. const next = input.charCodeAt(pos + 2);
  447. if (_isDigit(next)) {
  448. pos += 3;
  449. } else {
  450. return pos;
  451. }
  452. } else {
  453. return pos;
  454. }
  455. }
  456. } else {
  457. return pos;
  458. }
  459. cc = input.charCodeAt(pos);
  460. while (_isDigit(cc)) {
  461. pos++;
  462. if (pos === input.length) return pos;
  463. cc = input.charCodeAt(pos);
  464. }
  465. return pos;
  466. };
  467. /** @type {CharHandler} */
  468. const consumeLessThan = (input, pos, callbacks) => {
  469. if (input.slice(pos + 1, pos + 4) === "!--") return pos + 4;
  470. return pos + 1;
  471. };
  472. /** @type {CharHandler} */
  473. const consumeAt = (input, pos, callbacks) => {
  474. const start = pos;
  475. pos++;
  476. if (pos === input.length) return pos;
  477. if (_startsIdentifier(input, pos)) {
  478. pos = _consumeIdentifier(input, pos);
  479. if (callbacks.atKeyword !== undefined) {
  480. pos = callbacks.atKeyword(input, start, pos);
  481. }
  482. }
  483. return pos;
  484. };
  485. const CHAR_MAP = Array.from({ length: 0x80 }, (_, cc) => {
  486. // https://drafts.csswg.org/css-syntax/#consume-token
  487. switch (cc) {
  488. case CC_LINE_FEED:
  489. case CC_CARRIAGE_RETURN:
  490. case CC_FORM_FEED:
  491. case CC_TAB:
  492. case CC_SPACE:
  493. return consumeSpace;
  494. case CC_QUOTATION_MARK:
  495. case CC_APOSTROPHE:
  496. return consumeString(cc);
  497. case CC_NUMBER_SIGN:
  498. return consumeNumberSign;
  499. case CC_SLASH:
  500. return consumePotentialComment;
  501. // case CC_LEFT_SQUARE:
  502. // case CC_RIGHT_SQUARE:
  503. // case CC_COMMA:
  504. // case CC_COLON:
  505. // return consumeSingleCharToken;
  506. case CC_COMMA:
  507. return consumeComma;
  508. case CC_SEMICOLON:
  509. return consumeSemicolon;
  510. case CC_LEFT_PARENTHESIS:
  511. return consumeLeftParenthesis;
  512. case CC_RIGHT_PARENTHESIS:
  513. return consumeRightParenthesis;
  514. case CC_LEFT_CURLY:
  515. return consumeLeftCurlyBracket;
  516. case CC_RIGHT_CURLY:
  517. return consumeRightCurlyBracket;
  518. case CC_COLON:
  519. return consumePotentialPseudo;
  520. case CC_PLUS_SIGN:
  521. return consumeNumericToken;
  522. case CC_FULL_STOP:
  523. return consumeDot;
  524. case CC_HYPHEN_MINUS:
  525. return consumeMinus;
  526. case CC_LESS_THAN_SIGN:
  527. return consumeLessThan;
  528. case CC_AT_SIGN:
  529. return consumeAt;
  530. case CC_LOWER_U:
  531. return consumePotentialUrl;
  532. case CC_LOW_LINE:
  533. return consumeOtherIdentifier;
  534. default:
  535. if (_isDigit(cc)) return consumeNumericToken;
  536. if (
  537. (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
  538. (cc >= CC_UPPER_A && cc <= CC_UPPER_Z)
  539. ) {
  540. return consumeOtherIdentifier;
  541. }
  542. return consumeSingleCharToken;
  543. }
  544. });
  545. /**
  546. * @param {string} input input css
  547. * @param {CssTokenCallbacks} callbacks callbacks
  548. * @returns {void}
  549. */
  550. module.exports = (input, callbacks) => {
  551. let pos = 0;
  552. while (pos < input.length) {
  553. const cc = input.charCodeAt(pos);
  554. if (cc < 0x80) {
  555. pos = CHAR_MAP[cc](input, pos, callbacks);
  556. } else {
  557. pos++;
  558. }
  559. }
  560. };
  561. module.exports.eatComments = (input, pos) => {
  562. loop: for (;;) {
  563. const cc = input.charCodeAt(pos);
  564. if (cc === CC_SLASH) {
  565. if (pos === input.length) return pos;
  566. let cc = input.charCodeAt(pos + 1);
  567. if (cc !== CC_ASTERISK) return pos;
  568. pos++;
  569. for (;;) {
  570. pos++;
  571. if (pos === input.length) return pos;
  572. cc = input.charCodeAt(pos);
  573. while (cc === CC_ASTERISK) {
  574. pos++;
  575. if (pos === input.length) return pos;
  576. cc = input.charCodeAt(pos);
  577. if (cc === CC_SLASH) {
  578. pos++;
  579. continue loop;
  580. }
  581. }
  582. }
  583. }
  584. return pos;
  585. }
  586. };
  587. module.exports.eatWhitespaceAndComments = (input, pos) => {
  588. loop: for (;;) {
  589. const cc = input.charCodeAt(pos);
  590. if (cc === CC_SLASH) {
  591. if (pos === input.length) return pos;
  592. let cc = input.charCodeAt(pos + 1);
  593. if (cc !== CC_ASTERISK) return pos;
  594. pos++;
  595. for (;;) {
  596. pos++;
  597. if (pos === input.length) return pos;
  598. cc = input.charCodeAt(pos);
  599. while (cc === CC_ASTERISK) {
  600. pos++;
  601. if (pos === input.length) return pos;
  602. cc = input.charCodeAt(pos);
  603. if (cc === CC_SLASH) {
  604. pos++;
  605. continue loop;
  606. }
  607. }
  608. }
  609. } else if (_isWhiteSpace(cc)) {
  610. pos++;
  611. continue;
  612. }
  613. return pos;
  614. }
  615. };