Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isWhiteSpace(codePoint)) {
this.consumeWhiteSpace();
return WHITESPACE_TOKEN;
}
if (isDigit(codePoint)) {
this.reconsumeCodePoint(codePoint);
return this.consumeNumericToken();
}
if (isNameStartCodePoint(codePoint)) {
this.reconsumeCodePoint(codePoint);
return this.consumeIdentLikeToken();
}
return {type: TokenType.DELIM_TOKEN, value: fromCodePoint(codePoint)};
}
if (codePoint === LINE_FEED) {
this._value.splice(0, i);
return BAD_STRING_TOKEN;
}
if (codePoint === REVERSE_SOLIDUS) {
const next = this._value[i + 1];
if (next !== EOF && next !== undefined) {
if (next === LINE_FEED) {
value += this.consumeStringSlice(i);
i = -1;
this._value.shift();
} else if (isValidEscape(codePoint, next)) {
value += this.consumeStringSlice(i);
value += fromCodePoint(this.consumeEscapedCodePoint());
i = -1;
}
}
}
i++;
} while (true);
}
}
}
this.consumeBadUrlRemnants();
return BAD_URL_TOKEN;
}
while (true) {
const codePoint = this.consumeCodePoint();
if (codePoint === EOF || codePoint === RIGHT_PARENTHESIS) {
return {type: TokenType.URL_TOKEN, value: fromCodePoint(...value)};
} else if (isWhiteSpace(codePoint)) {
this.consumeWhiteSpace();
if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {
this.consumeCodePoint();
return {type: TokenType.URL_TOKEN, value: fromCodePoint(...value)};
}
this.consumeBadUrlRemnants();
return BAD_URL_TOKEN;
} else if (
codePoint === QUOTATION_MARK ||
codePoint === APOSTROPHE ||
codePoint === LEFT_PARENTHESIS ||
isNonPrintableCodePoint(codePoint)
) {
this.consumeBadUrlRemnants();
return BAD_URL_TOKEN;
} else if (codePoint === REVERSE_SOLIDUS) {
if (isValidEscape(codePoint, this.peekCodePoint(0))) {
value.push(this.consumeEscapedCodePoint());
} else {
this.consumeBadUrlRemnants();
private consumeEscapedCodePoint(): number {
const codePoint = this.consumeCodePoint();
if (isHex(codePoint)) {
let hex = fromCodePoint(codePoint);
while (isHex(this.peekCodePoint(0)) && hex.length < 6) {
hex += fromCodePoint(this.consumeCodePoint());
}
if (isWhiteSpace(this.peekCodePoint(0))) {
this.consumeCodePoint();
}
const hexCodePoint = parseInt(hex, 16);
if (hexCodePoint === 0 || isSurrogateCodePoint(hexCodePoint) || hexCodePoint > 0x10ffff) {
return REPLACEMENT_CHARACTER;
}
return hexCodePoint;
}
if (codePoint === EOF) {
private consumeName(): string {
let result = '';
while (true) {
const codePoint = this.consumeCodePoint();
if (isNameCodePoint(codePoint)) {
result += fromCodePoint(codePoint);
} else if (isValidEscape(codePoint, this.peekCodePoint(0))) {
result += fromCodePoint(this.consumeEscapedCodePoint());
} else {
this.reconsumeCodePoint(codePoint);
return result;
}
}
}
}
private consumeName(): string {
let result = '';
while (true) {
const codePoint = this.consumeCodePoint();
if (isNameCodePoint(codePoint)) {
result += fromCodePoint(codePoint);
} else if (isValidEscape(codePoint, this.peekCodePoint(0))) {
result += fromCodePoint(this.consumeEscapedCodePoint());
} else {
this.reconsumeCodePoint(codePoint);
return result;
}
}
}
}
private consumeStringSlice(count: number): string {
const SLICE_STACK_SIZE = 60000;
let value = '';
while (count > 0) {
const amount = Math.min(SLICE_STACK_SIZE, count);
value += fromCodePoint(...this._value.splice(0, amount));
count -= amount;
}
this._value.shift();
return value;
}