MCPcopy
hub / github.com/niklasvh/html2canvas / consumeToken

Method consumeToken

src/css/syntax/tokenizer.ts:332–510  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

330 }
331
332 private consumeToken(): CSSToken {
333 const codePoint = this.consumeCodePoint();
334
335 switch (codePoint) {
336 case QUOTATION_MARK:
337 return this.consumeStringToken(QUOTATION_MARK);
338 case NUMBER_SIGN:
339 const c1 = this.peekCodePoint(0);
340 const c2 = this.peekCodePoint(1);
341 const c3 = this.peekCodePoint(2);
342 if (isNameCodePoint(c1) || isValidEscape(c2, c3)) {
343 const flags = isIdentifierStart(c1, c2, c3) ? FLAG_ID : FLAG_UNRESTRICTED;
344 const value = this.consumeName();
345
346 return {type: TokenType.HASH_TOKEN, value, flags};
347 }
348 break;
349 case DOLLAR_SIGN:
350 if (this.peekCodePoint(0) === EQUALS_SIGN) {
351 this.consumeCodePoint();
352 return SUFFIX_MATCH_TOKEN;
353 }
354 break;
355 case APOSTROPHE:
356 return this.consumeStringToken(APOSTROPHE);
357 case LEFT_PARENTHESIS:
358 return LEFT_PARENTHESIS_TOKEN;
359 case RIGHT_PARENTHESIS:
360 return RIGHT_PARENTHESIS_TOKEN;
361 case ASTERISK:
362 if (this.peekCodePoint(0) === EQUALS_SIGN) {
363 this.consumeCodePoint();
364 return SUBSTRING_MATCH_TOKEN;
365 }
366 break;
367 case PLUS_SIGN:
368 if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
369 this.reconsumeCodePoint(codePoint);
370 return this.consumeNumericToken();
371 }
372 break;
373 case COMMA:
374 return COMMA_TOKEN;
375 case HYPHEN_MINUS:
376 const e1 = codePoint;
377 const e2 = this.peekCodePoint(0);
378 const e3 = this.peekCodePoint(1);
379
380 if (isNumberStart(e1, e2, e3)) {
381 this.reconsumeCodePoint(codePoint);
382 return this.consumeNumericToken();
383 }
384
385 if (isIdentifierStart(e1, e2, e3)) {
386 this.reconsumeCodePoint(codePoint);
387 return this.consumeIdentLikeToken();
388 }
389

Callers 1

readMethod · 0.95

Calls 15

consumeCodePointMethod · 0.95
consumeStringTokenMethod · 0.95
peekCodePointMethod · 0.95
consumeNameMethod · 0.95
reconsumeCodePointMethod · 0.95
consumeNumericTokenMethod · 0.95
consumeIdentLikeTokenMethod · 0.95
consumeWhiteSpaceMethod · 0.95
isNameCodePointFunction · 0.85
isValidEscapeFunction · 0.85
isIdentifierStartFunction · 0.85

Tested by

no test coverage detected